Reputation: 3146
yarn install -h
suggests that the -g
(global) option is DEPRECATED
. How am I supposed to indicate that I want a bunch of packages (from package.json
/ yarn.lock
files) to be installed globally?
Options I saw:
yarn global [command]
has things such as ls
and add
but not install
. add
only works with particular package names, if I understand correctly. I already have my yarn.lock
file ready, I don't want to repeat myself on the command line.yarn global add
each package one by one. Now my list of packages would be imperative instead of declarative.Specifically, I'd like to use one executable from one of those packages.
Upvotes: 104
Views: 124271
Reputation: 10997
Simply type
yarn global add nodejs
yarn global add nodejs mysql mongodb
Upvotes: 114
Reputation: 5494
Yarn 2, in its infinite wisdom, has removed yarn global
.
If you want to run a package, like firebase-tools
, you now do it via yarn dlx firebase-tools <parameters>
, instead of installing it then calling the installed package.
This is a terrible decision and I hope Yarn reverts it.
Upvotes: 8
Reputation: 803
For Global yarn install just type
yarn global add nodejs
Make sure that you already have Node installed on your system. Using this above command the yarn packages can be installed globally.
Note - "install" has been replaced with "add" now (this is for packages only)
Upvotes: 2
Reputation: 37
As containerization becomes the norm for application development locally AND for deployment to each environment, these conventions become less relevant. Each container image is its own server, and you can share the entire development environment with other developers using a Dockerfile and docker-compose (or other methods to containerize an application). Using this strategy, I can develop on the exact environment that gets deployed to prod, e.g. OS, libraries, versions, etc. But, developing a containerized application on a Mac or Windows machine requires a Virtual Machine + local host mounted directory to VM and then docker volume mounts from the VM. This runs terribly slowly when node_modules is part of that volume mount. Why can a developer not choose to do something that isnt 'recommended' if it improves their development experience? I think this should be revisited.
Upvotes: 1
Reputation: 21
Yarn adds all global package to a .yarn folder in your home: ~/.yarn/bin
so you have to export it as:
export PATH="$PATH:$HOME/.yarn/bin"
or add it to the .bashrc file in your home folder
Upvotes: 2
Reputation: 13547
You shouldn't. Installing globally is discouraged by Yarn, and there are very few situations where it's necessary, or even helpful.
As noted in the documentation:
For the vast majority of packages it is considered a bad practice to have global dependencies because they are implicit. It is much better to add all of your dependencies locally so that they are explicit and anyone else using your project gets the same set of dependencies.
If you are trying to use a CLI tool that has a bin you can access these in your ./node_modules/.bin directory.
If you really don't want to listen to the advice given, use
yarn global add <package>
However, don't expect to easily install a huge list of dependencies globally—it's hard to do by design, because it's not a good idea.
Instead, the intended flow with Yarn is:
./node_modules/.bin
where possibleUpvotes: 58
Reputation: 60875
npm install -g markdown-toc
Yarn decided not to support this functionality.
Upvotes: -7
Reputation: 90776
For those interested, here's a way to install and manage global applications installed via yarn.
First create a directory which will contain the applications, for example ~/.yarn-global
:
mkdir ~/.yarn-global
cd ~/.yarn-global
Then install your application from here:
yarn add yourapp
Finally open your profile file, i.e. .bashrc
or .bash_profile
and add the path to the bin directory:
export PATH="$PATH:$HOME/.yarn-global/node_modules/.bin"
From now on, any application you install in this directory will be available from anywhere in your shell.
Once this is done, you can even create a yarn-global
utility script that will only operate in this .yarn-global directory. For example:
sudo vim /usr/bin/yarn-global
sudo chmod 755 /usr/bin/yarn-global
And the script content would be:
#!/bin/bash
cd "$HOME/.yarn-global"
yarn $1 "$2"
Now you can do yarn-global add someapp
, yarn-global upgrade someapp
, etc.
Upvotes: 17