background

I recently changed to a new MAC (macOS Catalina 10.15.7). I need to reconfigure the development environment and install the Node version control tool NVM. The Chinese solutions found online are base-based and a bit out of date. Since macOS came to Catalina 10.15, the default Shell has changed to ZSH, so we directly use the official solution, see below for details.

1, install,

Github nVM-sh/NVM to see README. Md, I’m using cURL to install cURL.

The curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashCopy the code

Installation completed:

2. Identify problems

If you run the NVM command, you will see an error:

-bash: nvm: command not found
Copy the code

3. Find the answer

Moving on to the documentation, Troubleshooting finally finds the answer:

Since macOS 10.15, the default shell is ZSH and NVM will look for.zshrc to update, none is installed by default. Create one with touch ~/.zshrc and run the install script again.

After macOS 10.15, the default MAC shell changed from bash to ZSH, and NVM went back to the.zshrc file to update the configuration, but could not find it. The solution is to create a.zshrc file and reinstall NVM

touch ~/.zshrc
Copy the code

Re-execute the previous installation command:

The curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashCopy the code

At this point, the NVM command is executed successfully. At this point, check the ~/.zshrc file to see that it has been updated, and you can happily use NVM!

4. Common NVM commands

NVM install Version number // Download node version NVM use version number // Switch node version NVM ls // List locally downloaded version NVM ls-remote // List remote versionCopy the code

5. New problems

I thought it was over, but I found that every time I opened the console, there would be an exception message:

zsh compinit: insecure directories, run compaudit for list. Ignore insecure directories and continue [y] or abort compinit [n]? // Run the compaudit command % compaudit There are insecure directories: /usr/local/share/zsh/site-functions /usr/local/share/zshCopy the code

ZSH compinit: Insecure directories need to be turned off as follows:

% chmod g-w /usr/local/share/zsh 
% chmod g-w /usr/local/share/zsh/site-functions 
Copy the code

The link above may need to be turned over, so I will post a screenshot directly:

conclusion

It took some time to solve the above two problems, mainly because I was basically dealing with English, and my English was not very good. Based on the spirit of open source and sharing, I would like to share it with you. I hope it will be helpful to students who have similar problems. Thank you!