TL;DR
If you are managing node via nvm
, then probably the path to yarn binary is not included in the $PATH
variable. You should add this -
# Add this at the end (or after the $NVM_DIR initialization)
# in your profile - .bashrc | .zshrc | .profile, etc
export PATH="`yarn global bin`:$PATH"
at the end of your profile file (.zshrc
for me) or at least after the $NVM_DIR
initialization.
I have recently faced this issue and while searching for a solution, I landed up here.
Here is what my environment looks like:
- OS: Ubuntu 20.04
- Shell:
zsh
- NodeJS: managing it via
nvm
, and NOT apt
.
After going through all the answers, I was not keen on uninstalling anything. So I tried to dig a bit deeper.
I installed yarn
via npm install -g yarn
command. So the first thing I wanted to verify was the location of the yarn
binary. To do this, I ran the command where yarn
which lists the installation path for the yarn
binary.
$ where yarn
/home/<user_name>/.nvm/versions/node/v16.11.1/bin/yarn
Then it hit me. In my .zshrc
file, I had added the yarn global bin
command (which spills out the directory of all the global packages installed by yarn) at the top like so:
# Top of my .zshrc file
export PATH="`yarn global bin`:$HOME/bin:/usr/local/bin:$PATH"
and as per the installation instruction of nvm
, the $NVM_DIR
(the variable which holds the nvm
directory path) was added at the end of my .zshrc
file.
So when I was starting up my shell, it was actually trying to load the yarn
command (present inside the nvm
directory) even before loading the $NVM_DIR
path.
To solve this, I tweaked my .zshrc
file and moved the yarn global bin
command after the $NVM_DIR
like this:
# Top of my .zshrc file
export PATH="$HOME/bin:/usr/local/bin:$PATH"
# ...
#
# Something in between
#
# ...
# Bottom of my .zshrc file
export NVM_DIR="${HOME}/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Here is where I have added the path to yarn global
export PATH="`yarn global bin`:$$PATH"
I hope that this would be of help.
sudo
. If you have your paths set up correctly then this issue is because of the users. – Concentrate