Node.js can be installed first by installing Node Version Manager (NVM), because NVM can manage different versions of Node.js, or you can switch to the desired Version.

Install the NVM

Using cURL to install or update an NVM:

(Do not use Homebrew because it is not supported)

Open iTrem2 and enter the following command

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

After entering the above instructions, you will install NVM in ~/.nvm. It doesn’t matter if you don’t understand this, then you will open Finder and cut to your own directory

Basically you don’t see anything, so if you want your terminal or iTerm2 to be able to execute NVM, you have to adjust the environment variable. The environment variable adjustment is set under the relevant terminal, but the terminal is usually hidden. So now in the Finder screen hit Command + Shift+. The > button will display the hidden file

The next default terminal is.bash_profile, while iTrem2 uses ZSH, so.zshrc is just a matter of adding the following environment variables at the end of each 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
Copy the code

This allows you to point to NVM and use it (if you don’t have a.bash_profile or.zshrc underneath, create one yourself). Finally, open the terminal and type NVM to see which instructions you can use

In OS X, if NVM: Command not found is displayed after the installation command is executed, it indicates that the.bash_profile file is not found on your system. You can create a file with touch ~/.bash_profile and then execute the install command again. If this still doesn’t work, open.bash_profile and add:

source ~/.bashrc
Copy the code

Check whether the NVM is installed successfully

The following instructions can be used:

command -v nvm
Copy the code

If the installation is successful, NVM is output.

You cannot use which NVM to check because NVM is a following shell function, not a executable binary.

As for NVM common instructions are the following

  • NVM install [Node version number] – Installs a specific version of NVM
  • NVM List – Lists the installed list
  • NVM use [Node version number] – Switch to a specific node version (installed version only)

Clang: error: no such file or directory: ‘CXX=c++’ clang: error: no such file or directory: ‘CXX=c++

clang: error: no such file or directory: 'CXX=c++'
Copy the code

Solution: Enter in iTrem2

arch -x86_64 zsh
Copy the code

Then install the specified Node version

Oh Yeah ! Finished!