Installing Multiple Versions Of Node Js In SUSE Linux Enterprise Server ( SLES 15 )
In SUSE Linux Enterprise Server (SLES), installing multiple versions of Node Js is much easier than installing Node Js from Official Repository. Node Version Manager (NVM) allows you to install multiple versions of Node Js without adding any version-specific or OS-specific repository. In this article, let us see how to install multiple Node Js versions in SLES 15 with NVM.
NVM For Multiple Versions Of Node Js
Node Version Manager (NVM) allows you to install multiple versions of Node Js in all Operating Systems. In SLES, to install Node JS “Web and Scripting Module” has to be enabled. But, to install Node Js through NVM, enabling “Web and Scripting Module” is not required.
Installing Node Version Manager( NVM)
To install NVM, execute the command “curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
” in the terminal. Wait for the completion of the installation and close and re-open the terminal. To check if NVM is installed correctly, execute the command nvm -v
in the terminal, this would return the version number of nvm. If you receive a command not found
error, execute the command “source ~/.bashrc
“.
If you still get an error, ensure that the below lines are added to the .bashrc
file.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
.bashrc
file requires a re-load of the file by executing the command source ~/.bashrc
Installing & Switching Node Js Versions
The below are some of the basic commands that you should be aware of to effectively use NVM.
# Installs the latest version of Node Js
# It is 16.10 at the time of writing
nvm install node
# Install latest LTS version of Node Js
# It is 14.18 at the time of writing
nvm install --lts
# To view the list of Node Js versions installed
nvm ls or nvm list
# To switch to a specific version of Node
nvm use node # switches to the default version
nvm use 16 or nvm use 14 # specify a version number
# To use the Node Js version directly installed ( if any)
nvm use system
# Set a specific version as the default version
# The first installed version is considered
# as the default version of Node Js
nvm alias default 14 # set version 14 as default Node Js
More information on nvm commands can be found here.
.nvmrc
NVM also provides an easy way to switch between different versions of Node Js in a project by specifying the version number in a file named .nvmrc
. Place this file inside the project folder and execute the command nvm use
. This would switch the Node version to the one specified in the file.
Leave a comment