MacOS: Install and set-up NVM
26, November 2019There are a lot of reasons to install NVM and switch between each Node version. Here is the solution to do it on MacOS...
NVM, or Node Version Manager, is a tool that allow user to manage on his system many versions of Node.
When you do application maintenance, stacks evolving very quickly, you have to be able to go back to an old version / configuration. For instance, if you develop with Ionic v3, you probably will not have the time, the possibility, the budget to upgrade to the v4 version. But you will still have to use it to generate the assets, the resources ... which correspond to the last requirements of the stores.
Homebrew installation
Homebrew is used to install NVM. If you have'nt this tool, please install it.
Otherwise, update your Homebrew version with the following command:
brew update
NVM installation
To install NVM, execute the following commands:
brew install nvm
mkdir ~/.nvm # NVM working directory
NVM configuration
The article bellow depends of your shell installation / configuration. From the MacOS Catalina, ZSH is used by default. Click here for more information.
Execute the following commands according your shell:
nano ~/.bash_profile # If you use bach
nano ~/.zprofile # If you use ZSH
Add the following lines in file:
export NVM_DIR=~/.nvm # Define the global variable $NVM_DIR
source $(brew --prefix nvm)/nvm.sh # Set 'nvm' command for console
source $(brew --prefix)/Cellar/nvm/$(nvm --version)/nvm.sh # Set the 'Node' commands for console
Save then load the file with the following commands:
source ~/.bash_profile # If you use bach
source ~/.zprofile # If you use ZSH
Node installation
When NVM is installed and configured, you can install Node.
To check that NVM is correctly installed, execute the following command: nvm --version
.
Then execute:
nvm install 8.12.0 # To isntall the Node version 8.12.0
nvm install 12.13.0 # To isntall the Node version 12.13.0
#...
Optimize the configuration
When some versions of Node are installed, it is interesting to launch the right version at shell startup and avoid using the instruction nvm use
.
To do that, you shall define the alias default with the following command:
nvm alias default 8.12.0 # If you want that Node v8.12.0 is the default used version
I hope all this has been helpful.
See you in the next article.
Add a comment