Encountered a problem: zsh: command not found: yarn
solution
Prerequisite: Node has been installed on the computer
node -v
Global installation
npm install yarn -g
If there is no problem in this step, you don’t need to look down, you can directly execute the yarn command
如果遇到报错The operation was rejected by your operating system.npm ERR! It is likely you do not have the permissions to access this file as the current user
XXXX@CN_C02GXXX6M ~ % npm i yarn -g
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/yarn
npm ERR! dest /usr/local/lib/node_modules/.yarn-Jrexx8nI
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/yarn' -> '/usr/local/lib/node_modules/.yarn-Jrexx8nI'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/yarn' -> '/usr/local/lib/node_modules/.yarn-Jrexx8nI'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/lib/node_modules/yarn',
npm ERR! dest: '/usr/local/lib/node_modules/.yarn-Jrexx8nI'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
Solution one for error reporting:
sudo npm i yarn -g
Solution to the error report 2: (Only under the strict control of computer permissions, the permissions cannot be obtained)
step1: View the npm global file installation address
XXX@CN_CXXXMD6M ~ % npm list -g
/usr/local/lib
├── @quasar/[email protected]
├── [email protected]
├── [email protected]
└── [email protected]
step2: From the same directory on other people's computers, copy two files, one is the shortcut file of the command, and the other is the path file pointed to by the environment variable, paste it to the same location on your computer
-
command snapshot file
-
The file pointed to by the global command
step3: Open the environment variable configuration file and configure the environment variable
vim ~/.bash_profile
Paste the following content into the environment variable file,
export PATH=/usr/local/lib/node_modules/yarn/bin/:$PATH
Save the edit of .bash_profile and execute the file
source ~/.bash_profile
Problem solved, you're done
Re-open the command line, you can use yarn
yarn -v
I will write here today~
- Friends, ( ̄ω ̄( ̄ω ̄〃 ( ̄ω ̄〃)ゝ See you tomorrow~~
- Everyone be happy every day
Everyone is welcome to point out where the article needs to be corrected~
Learning is endless, cooperation is win-win