With the latest macOS update comes zsh (or z shell) and with it comes some issues, one of them is how complicated it is to install NVM so here is how to do it.
Before you get started, make sure that you have zsh as your current running shell, to do so run the following in your terminal: echo $0
, if you're using zsh then you should see the following output -zsh
.
Restart terminal and install the latest version of Node. Nvm install node. Run the final command to confirm node is installed. Nvm use node node -v && npm -v #confirm the install worked. The issue with Hombrew and Catalina, re-installing npm via NVM still persist. The command compaudit xargs chmod g-w was the best method that worked for my system. Copy link torgeir commented Jan 25, 2021. To install brew, visit and follow the instructions; Before installing anything with brew, it’s good practice to run brew update first. If your brew install is messed up, brew doctor can help restore a proper install. Using brew to install node. This command will install node using brew.
Best way to install and use nvm on Mac As a developer, switch version of Node always for capable client?s demand or environment without review code again. And nvm is one way of switch versions of node. 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 /.bashprofile # If you use bach nano /.zprofile # If you use ZSH. Add the following lines in file.
Start downloading and running the install script for NVM, you can find more about this in its repo (https://github.com/nvm-sh/nvm):
After the installation, you'll need to add the code below to the startup file, this sets up the alias for NVM to make sure that it's always available on your shell even after it was closed and opened again
Open the startup file using nano, paste the code above then save the file.
Open a new terminal window and test your nvm installation by running nvm --version
.
NVM is a shell script that allows you to easily install & manage NodeJS. In this article, we will look at how to install NVM on Mac with Homebrew utility. If you have not installed Homebrew on your Mac, you can easily do so by opening the terminal and running the following command. It will download & install homebrew for you.
How to Install NVM on Mac with Brew
Here are the steps to install NVM on Mac with Homebrew.
1. Remove Existing NodeJS
If you have already installed NodeJS earlier, then open terminal and run the following commands to uninstall them first. If there is no NodeJS installed on your system, you can skip this step.
2. Install NVM
Run the following command to update NVM package list and install NVM.
Install Nvm Mac Catalina Download
Create directory for NVM in /home.
Next, we need to configure environment variables to point to NVM. Open bash_profile file in text editor. Alternatively, you may open ~/.zshrc for macOS Catalina or later.
Install Nvm Mac Catalina Free
Add the following lines to this file.
Save and close the file by typing Esc, then entering :wq.
Run the following command to reload bash_profile. It will also ensure that environment variable is updated every time you login.
How Install Nvm On Mac
3. Install NodeJS with NVM
NVM is a very handy tool to install & manage NodeJS on your system. You can list the available NodeJS versions with the following command.
Next, if you want to download and install the latest NodeJS version, just run the following command.
If you want to download & install a specific version of NodeJS like Node 12.x, run the following command.
After installation, you can verify it with the following command.
If you have multiple versions of NodeJS installed on your system, you can set the default version with the following command. Here is an example to use Node 12.x as default version.
You can always install different NodeJS versions on same system and manage them easily using NVM.
That’s it. In this article, we have learnt how to install and manage NodeJS using NVM, in Mac. Although you can install NodeJS separately, without NVM, it is advisable to NVM since it allows you to easily manage multiple versions of NodeJS, making it convenient to test and upgrade to new versions, or rollback to older versions, as you need.
Also read:
Shell Script to Start, Stop & Restart Tomcat Automatically
Shell Script to Backup MySQL Database
Htaccess Redirect If URL Contains String/Word
How to Change Root Password in Linux
How to Run Shell Script as Cron Job