DEV Community

Gabriel Wu
Gabriel Wu

Posted on • Edited on

3 1

`yarn global` under the hood

yarn

yarn global helps us manage global npm packages, which is especially useful for CLI tools. How does it work?

By default, it will create a directory at ~/.config/yarn/global (on OSX and non-root Linux), and if you enter the directory, you will find its structure like this:

├── node_modules
├── package.json
├── yarn-error.log
└── yarn.lock

And in package.json, all global packages are defined as dependencies, just like what you are familiar with in a normal JS/TS project.

In this directory, you can do whatever you would normally do, like yarn add, yarn remove, yarn upgrade, yarn upgrade-interactive, etc.

The key point that makes yarn global different is that it handles the binaries by creating symlinks in the directory you specify with --prefix option. On OSX and non-root Linux, the default prefix is /usr/local, which means the binaries will be symlinked to /usr/local/bin, which is usually in the enviroment variable $PATH. So if you prefer using a custom directory for symlinks, do make sure that the directory is in $PATH.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay