I recommend using Node Version Manager:
NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.
Installing Node Version Manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Once you have Node Version Manager installed
- Confirm the available remote versions by running
nvm ls-remote - Run in your terminal
nvm install <version>for example,nvm install 18to install version 18 of Node - List installed versions with
nvm list - Run
nvm use 18to start using version 18 of Node - Note: you can be more explicit, for example:
nvm install 14.17.0
I recommend using Node Version Manager:
NB: Node Version Manager (nvm) allows you to install multiple node versions and choose between them depending on which software you want to support; that is, manage multiple node versions.
Installing Node Version Manager
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Once you have Node Version Manager installed
- Confirm the available remote versions by running
nvm ls-remote - Run in your terminal
nvm install <version>for example,nvm install 18to install version 18 of Node - List installed versions with
nvm list - Run
nvm use 18to start using version 18 of Node - Note: you can be more explicit, for example:
nvm install 14.17.0
Install nodejs v20 on Debian and Ubuntu based distributions
step 1 : Download and import the Nodesource GPG key
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
step 2 : Create deb repository
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
optional: here we are installing nodejs v20 but if you want to install v18 change NODE_MAJOR=18 in above command. Similarly if you want to install nodejs v16 then change NODE_MAJOR=16.
step 3 : Run Update and Install
sudo apt-get update
sudo apt-get install nodejs -y
congratulations you just installed nodejs
To uninstall nodejs
sudo apt-get purge nodejs &&\
rm -r /etc/apt/sources.list.d/nodesource.list &&\
rm -r /etc/apt/keyrings/nodesource.gpg
node.js - installing node lts with nvm on windows - Stack Overflow
In an Ubuntu 22 I can't install node latest version
node.js - How to install nvm on Mac? - Stack Overflow
node.js - nvm install node fails to install on macOS Big Sur M1 Chip - Stack Overflow
Videos
Installing the latest version of node using nvm:
Install the latest nvm through its Github repo:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.bashrc
check the latest version of node and select it:
nvm list-remote
Out:
...
v20.15.0 (LTS: Iron)
v20.15.1 (LTS: Iron)
v20.16.0 (Latest LTS: Iron)
v21.0.0
v21.1.0
v21.2.0
v21.3.0
v21.4.0
v21.5.0
v21.6.0
v21.6.1
v21.6.2
v21.7.0
v21.7.1
v21.7.2
v21.7.3
v22.0.0
v22.1.0
v22.2.0
v22.3.0
v22.4.0
v22.4.1
v22.5.0
v22.5.1
v22.6.0
Install the desired version of node:
nvm install v20.16.0
INSTALL (Node Version Manager) be following command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashNow, reopen your terminal, or "
exit" command if you server ssh and reconnectGet packages by following command:
nvm install 20Veryfiy node by:
node -v# should print v20.16.0Finally check the npm:
npm -v # should print '10.8.1'
Gongrates! You have done!
For nvm-windows (Windows)
To install and use the latest LTS release of Node.js:
nvm install lts
nvm use lts
For nvm (Linux, OSX, WSL)
To install and use the latest LTS release of Node.js:
nvm install --lts
nvm use --lts
To install and use a specific LTS release of Node.js:
nvm install lts/erbium
nvm use lts/erbium
Following this github comment, just run nvm list available and then nvm install x.y.z
Don't forget to nvm use x.y.z after you're done. I used this manual - in case it helps.
To resolve this issue, ensure that nvm is properly set up in your shell configuration. Since you are using zsh, add the following lines to your .zshrc file:
brew upgrade
brew install nvm
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "$(brew --prefix nvm)/nvm.sh" ] && \. "$(brew --prefix nvm)/nvm.sh"' >> ~/.zshrc
echo '[ -s "$(brew --prefix nvm)/etc/bash_completion.d/nvm" ] && \. "$(brew --prefix nvm)/etc/bash_completion.d/nvm"' >> ~/.zshrc
source ~/.zshrc
After running these commands, nvm should be set up correctly. You can verify the installation by checking the nvm version:
$ nvm --version
Looking at the warning which you added in your question, I surmise that nvm is installed on your machine but may not have been setup properly. Nevertheless, adding full steps for you to verify which one you missed and fix the same.
1. Confirm nvm is installed
Before making changes, check if nvm exists:
# confirm nvm is installed
$ brew list | grep nvm
# if the above doesn't return anything, install nvm
$ brew install nvm
2. Ensure your system is in good shape
Sometimes Homebrew issues prevent nvm from working properly. For that run:
$ brew doctor
# If you see any warnings, follow the suggested fixes and
# rerun brew doctor until everything looks good.
3. Create the nvm directory (if missing)
$ mkdir -p ~/.nvm
4. Add nvm to your shell configuration
Manually add these lines to ~/.zshrc:
export NVM_DIR="$HOME/.nvm"
[ -s "$(brew --prefix nvm)/nvm.sh" ] && . "$(brew --prefix nvm)/nvm.sh"
[ -s "$(brew --prefix nvm)/etc/bash_completion.d/nvm" ] && . "$(brew --prefix nvm)/etc/bash_completion.d/nvm"
Save the file and reload the configuration:
$ source ~/.zshrc
5. Verify and Restart
Check if nvm is now working:
$ nvm -v
If you still get an error, restart your terminal and try again. Sometimes failing to do this might also lead to issues.
If you have installed nvm using homebrew and are trying to install the node using command nvm install <some_version>, you will face errors on apple silicon machines (ARM) for versions lower than 15. Node versions older than 15 do not work on apple silicon machines (ARM) because ARM architecture is not supported.
For anything under v15, you will need to install node using Rosetta 2.
- How to open terminal in Rosetta2 mode: Go to Application -> Right click on terminal app -> Get Info -> Select "Open using Rosetta" -> Restart Terminal
- In Terminal, write ->
arch -x86_64 zsh
Now you will able to install any version of node (even multiple versions)
it wasn't an issue while i was trying to install node 12.X.X but below that it was a big pain so i followed below steps and it worked for me
Uninstalled nvm if it’s already installed using Homebrew.
brew uninstall nvm
brew cleanup
Install Rosetta
softwareupdate --install-rosetta
Make terminal/iTerm2 to open in Rosetta mode
got to Application (-> utilities) -> right click on terminal app -> get Info -> Select "Open using Rosetta" -> Restart Terminal
In Terminal run a command
arch -x86_64 zsh
Make sure machine has .zshrc file if not just create one
cd ~
touch .zshrc
Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Restart the terminal and check if nvm is installed successfully by running
nvm -v
Then install Node with nvm as usual
nvm install 10