Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
strarsis opened this issue Feb 12, 2018 · 18 comments
Open

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

strarsis opened this issue Feb 12, 2018 · 18 comments

Comments

@strarsis
Copy link

strarsis commented Feb 12, 2018

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)

@ghost ghost assigned rally25rs Feb 12, 2018
@ghost ghost added the triaged label Feb 12, 2018
@strarsis strarsis changed the title yarn doesn't add global bin/ to $PATH yarn doesn't add global packages bin/ to $PATH Feb 12, 2018
@jhudsoncedaron
Copy link

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.

@strarsis
Copy link
Author

strarsis commented Feb 26, 2018

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

@kylebakerio
Copy link

kylebakerio commented Apr 1, 2018

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

@saper
Copy link

saper commented Jun 9, 2018

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.

@HKhademian
Copy link

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

@strarsis
Copy link
Author

strarsis commented Jun 22, 2018

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

doxanthropos added a commit to doxanthropos/website that referenced this issue Oct 14, 2018
The install directory is not added to the PATH automatically, so it would be nice to let the users know, they have to change that to be able to use the globally installed packages.
See: yarnpkg/yarn#5353
Haroenv pushed a commit to yarnpkg/website that referenced this issue Oct 15, 2018
The install directory is not added to the PATH automatically, so it would be nice to let the users know, they have to change that to be able to use the globally installed packages.
See: yarnpkg/yarn#5353
@nebrelbug
Copy link

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.

@voliva
Copy link

voliva commented Feb 5, 2019

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"

@nimaiwalsh
Copy link

nimaiwalsh commented Nov 17, 2019

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"

@bertho-zero
Copy link
Contributor

Should be

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

instead of

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

@JBudny
Copy link

JBudny commented Nov 20, 2020

@nimaiwalsh it's because you misused yarn cli. Yarn global and yarn add are two different commands.

yarn global

Install packages globally on your operating system.

yarn add

Installs a package and any packages that it depends on.

In order to install the package globally with yarn just use:
yarn global add <application> - This installs package application in your global directory
instead of:
yarn add global <application> - This installs package named global and application in your local directory

@meatnordrink
Copy link

For my, because it didn't add it to my path, yarn global bin didn't work as a bash variable; I had to actually copy the location listed by npm install -g yarn and use that for the line in .bashrc:

export PATH="/usr/local/lib/node_modules/yarn/bin:$PATH"

@orimdominic
Copy link

Just a reminder that if you're using zsh, you should make this change in .zshrc, or whatever the config file is for the terminal in use

@symant233
Copy link

for fish shell (<3.2.0), run this command once (ref):

set -U fish_user_paths (yarn global bin) $fish_user_paths

@kay-o
Copy link

kay-o commented Apr 15, 2022

if you are using oh-my-zsh and nvm, be sure you add nvm as a plugin in ~/.zshrc
plugins=(git nvm)

@shubhangicatch
Copy link

How to fix this issue in mac?

Error: ENOTDIR: not a directory, open '/Users/shubhangishukla/.config/yarn'
at Object.openSync (node:fs:584:3)
at readFileSync (node:fs:452:35)
at /Users/shubhangishukla/.yarn/lib/cli.js:97395:58
at Array.map ()
at parseRcPaths (/Users/shubhangishukla/.yarn/lib/cli.js:97393:78)
at Object.findRc (/Users/shubhangishukla/.yarn/lib/cli.js:97407:10)
at getRcConfigForCwd (/Users/shubhangishukla/.yarn/lib/cli.js:56965:74)
at /Users/shubhangishukla/.yarn/lib/cli.js:88756:56
at Generator.next ()
at step (/Users/shubhangishukla/.yarn/lib/cli.js:310:30)

Yarn was installed, but doesn't seem to be working :(.

@shubhangicatch
Copy link

For my, because it didn't add it to my path, yarn global bin didn't work as a bash variable; I had to actually copy the location listed by npm install -g yarn and use that for the line in .bashrc:

export PATH="/usr/local/lib/node_modules/yarn/bin:$PATH"

For my, because it didn't add it to my path, yarn global bin didn't work as a bash variable; I had to actually copy the location listed by npm install -g yarn and use that for the line in .bashrc:

export PATH="/usr/local/lib/node_modules/yarn/bin:$PATH"

@meatnordrink I am facing similar issue while running yarn or yarn install from terminal Error: ENOTDIR: not a directory, open '/Users/shubhangishukla/.config/yarn'
at Object.openSync (node:fs:584:3)
at readFileSync (node:fs:452:35)
at /usr/local/lib/node_modules/yarn/lib/cli.js:97395:58
at Array.map ()
at parseRcPaths (/usr/local/lib/node_modules/yarn/lib/cli.js:97393:78)
at Object.findRc (/usr/local/lib/node_modules/yarn/lib/cli.js:97407:10)
at getRcConfigForCwd (/usr/local/lib/node_modules/yarn/lib/cli.js:56965:74)
at /usr/local/lib/node_modules/yarn/lib/cli.js:88756:56
at Generator.next ()
at step (/usr/local/lib/node_modules/yarn/lib/cli.js:310:30)

Still not resolved .

@meatnordrink
Copy link

@shubhangicatch , did the steps I described not address the issue? (Did you try adding that path to the PATH variable in your .bashrc?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests