[yarn for MAC] error "-bash: yarn: command not found" is reported, then install yarn

install yarn

The following methods of installing yarn are一个不行就直接换它

Law one

Prerequisite: The computer has installed node to use this method

node -v

Global installation:

npm install yarn -g

If you enter: yarn --versionyou can view the version number description, the installation is successful.

Error report

If you encounter the following errors:

cengguilideMacBook-Pro:~ zengguili$ npm install yarn -g
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/yarn
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/yarn'
npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/yarn'] {
    
    
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/yarn'
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.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/zengguili/.npm/_logs/2023-03-13T07_48_40_378Z-debug.log

Solution one :

sudo npm i yarn -g

Solution two :

(Only under strict control of computer permissions, permissions cannot be obtained)

  1. View npm global file installation address
XXX@CN_CXXXMD6M ~ % npm list -g                    
/usr/local/lib
├── @quasar/cli@1.3.2
├── corepack@0.14.1
├── npm@8.19.2
└── yarn@1.22.18
  1. 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, and paste it to the same location on your computer
  2. Open the environment variable configuration file and configure the environment variable
vim ~/.bash_profile
  1. Paste the following content into the environment variable file,
export PATH=/usr/local/lib/node_modules/yarn/bin/:$PATH
  1. Save the edit of .bash_profile and execute the file
source ~/.bash_profile
  1. The problem is solved, you're done, use the following command line to reopen, you can use yarn
yarn -v

Solution three :

  1. Open a file with these two commands
touch ~/.bash_profile   //touch的意思是没有就创建;.bash_profile这是系统临时的环境变量, 

sudo open -e ~/.bash_profile
  1. Then export PATH=/usr/local/lib/node_modules/yarn/bin/:$PATHwrite it into the opened file, save it, and execute the command again:
source ~/.bash_profile
  1. Check the version again
yarn --version

insert image description here

law two

Install using mac script

curl -o- -L https://yarnpkg.com/install.sh | bash  

PS: Simple and fast, it is strongly recommended to try, especially for the domestic network environment

Law three

install using homebrew

Prerequisite: brew is installed

brew install yarn 

PS: It is recommended to try in a good network environment

Guess you like

Origin blog.csdn.net/qiqizgl777/article/details/129496430