Method 1 – Using NVM:
sudo apt update sudo apt upgrade sudo apt install wget wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash nvm install --lts # install the latest LTS version of node js nvm use --lts # use the latest LTS version of nodejs node --version npm --version
Add the following lines to your ~/.zshrc
or ~/.bashrc
:
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 source ~/.bashrc
Finally, use nvm to install the latest version of node:
nvm install node nvm use node node --version v14.13.0 npm --version 6.14.8 nvm list nvm help
Method 2 – Using apt and just install the latest version of node
sudo apt install nodejs