Install the Distro-Stable Version of Node.js with YUM
In order to download this version, we will use the yum package manager.
- Update your yum packages:sudo yum update
- Install Node.js:sudo yum install nodejs
- Verify the current version of Node.js:node –version
- Install npm (Node Package Manager):sudo yum install npm
Install Node.js using NVM
Instead of using yum, you can install Node.js with a tool called nvm, which stands for “Node.js Version Manager”.
NVM lets you install multiple different versions of Node.js. This way, you have more control over your environment for whatever your project needs. NVM will also give you on-demand access to the latest versions of Node.js, and the ability to use previous releases that your application may be dependent on.
- Run yum update:sudo yum update
- Install tar:sudo yum install tar
- Download and install the installation script.
Download the nvm installation script from the project’s GitHub page:wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
This will download the script and execute it. It will install into a subdirectory of your home directory at ~/.nvm. It also adds the essential lines to your ~/.profile file to use the file with bash.
Note: This command will pull from the Github Master page so that it is always up to date, but you can use previous versions by finding the URL on that GitHub repository.
- Update your current session:source ~/.profile
- List available Node.js versions.
Now that nvm is installed, you can install isolated Node.js versions:nvm ls-remote. . .
- Install the version of Node.js that you want to use.
In this example, the newest version is v7.1.0. If you wanted to install V7.1.0 you can do so by using the nvm install command. If there is a newer version available, use that version.nvm install 7.1.0
- After the command runs, your desired version of Node.js will be installed.
- Typically, nvm will default to the newest version, but you can explicitly tell nvm to use a previous version by using the following syntax – where the highlighted portion is the version you wish to run:nvm use 7.0.0
- When using nvm to install Node.js, the executable is simply called node. You can find out what Node.js version is being used by the shell by typing:node -v
- This will display the version being used:v.7.1.0
- If you have multiple versions of Node.js, you can determine the installed version by typing:nvm ls
- To set a specific Node.js as default, you can use the following syntax where the highlighted portion of the text is the desired version:nvm alias default 7.1.0
- That version will be automatically selected when a new session is generated. You can also reference it using an alias such as:nvm use default
Each version of Node.js will keep track of its own packages and uses npm to manage them.
- If you want to make that package available globally to all your Node.js projects, you can simply add the -g flag:npm install -g express
After that command has been run, the package will be installed in:~/.nvm/node_version/lib/node_modules/package_name
- Using the global installation will allow you to run the commands from the command line. However, you will have to link the package into your local sphere to require it from within an application. In this example, we are linking Express.js to our current project:npm link express
- For any other information about the NVM command, you can use help:nvm help