yarn doesn't add global packages bin/ to $PATH

Created on 12 Feb 2018  路  10Comments  路  Source: yarnpkg/yarn

What is the current behavior?
yarn doesn't add the directory for commands of globally installed packages (~/.yarn/bin) to $PATH,
hence these commands cannot be invoked after having them added using yarn.

What is the expected behavior?
PATH is updated to include ~/.yarn/bin by yarn during initial installation or during global package installation so commands can be invoked without requiring extra changes to config/.bashrc.

Please mention your node.js, yarn and operating system version.
node v9.2.0
yarn 1.3.2
WSL (Bash on Windows)

cat-bug help wanted triaged

Most helpful comment

if you use (install) yarn from npm you must add export PATH="$(yarn global bin):$PATH" to end of your .bashrc

All 10 comments

Reproduced. Installing the .msi set it up for the first user correctly; however the path entry wasn't made by yarn for the next user.

@jhudsoncedaron: This also seems to be an issue when using yarn on
WSL (Bash on Windows) (similar to Ubuntu), the PATH is not added.

same, both local and on google cloud machine. It's lame. (both debian stretch 9)

I wonder if this is not part of a bigger problem - when I have something, e.g. node-sass installed globally with yarn global add node-sass it will be installed locally even the global module would fulfull requirements.

if you use (install) yarn from npm you must add export PATH="$(yarn global bin):$PATH" to end of your .bashrc

@HKhademian: Yes, but this should be actually added by the installer automatically.

For anyone else who's having the same issue, I solved it by running yarn global bin like @HKhademian suggested, then copying that into the Path in system environment variables.

I've had some issues on Ubuntu 18.10 by using @HKhademian solution: When the internet is down I couldn't log into my account, because yarn global bin throws a warning

You don't appear to have an internet connection. Try the --offline flag to use the cache for registry queries.

And for some reason this is caught as an error in the profile script and blocks you from logging in. Solution is to do as suggested

export PATH="$(yarn global bin --offline):$PATH"

Hi Everyone,

Yarn won't install in its specified Global directory, nor does zsh pick up the command for the installed global package.

I'm usingNVM and Yarn installed with curl -o- -L https://yarnpkg.com/install.sh | zsh

yarn global bin returns Users/nimaiwalsh/.yarn/bin

yarn global dir returns /Users/nimaiwalsh/.config/yarn/global

However when I yarn yarn add global <application> it installs packages in a root node_modules folder /Users/nimaiwalsh/node_modules instead of the yarn global dir. Secondly, the ZSH command does not recognise the installed package without preceding it with yarn. eg create-react-app is not recognised with ZSH while yarn create react app is.

I'm wanting all global yarn installs to go to /Users/nimaiwalsh/.config/yarn/global

The only WORKAROUND for me at the moment is running the global command from bash and not zsh.

Below is my .zshrc file:

# NVM
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh

# Path to Bash profile
# source ~./bash_profile

#MAVEN
export PATH=/Applications/apache-maven-3.6.2/bin:$PATH

#YARN
export PATH="$PATH:/Users/nimaiwalsh/.yarn/bin"

#ANDROID STUDIO
export ANDROID_HOME=/Users/nimaiwalsh/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH

# Path to your oh-my-zsh installation
# All other oh-my-zsh below here
export ZSH="/Users/nimaiwalsh/.oh-my-zsh"

ZSH_THEME="agnoster"

source $ZSH/oh-my-zsh.sh

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="/Users/nimaiwalsh/.sdkman"
[[ -s "/Users/nimaiwalsh/.sdkman/bin/sdkman-init.sh" ]] && source "/Users/nimaiwalsh/.sdkman/bin/sdkman-init.sh"
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

Should be

export PATH="$PATH:$(yarn global bin)"

instead of

export PATH="$(yarn global bin):$PATH"
Was this page helpful?
0 / 5 - 0 ratings