HomeLinuxSet up and Handle A number of Node.js Variations in Linux

Set up and Handle A number of Node.js Variations in Linux


Node Model Supervisor (NVM in brief) is an easy bash script to handle a number of energetic node.js variations in your Linux system. It means that you can set up a number of node.js variations, and look at all variations out there for set up and all put in variations in your system.

Nvm additionally helps working of a particular node.js model and it might probably present the trail to the executable to the place it was put in, and far more.

On this article, we are going to clarify the way to set up Node Model Supervisor (NVM) to handle a number of energetic node.js variations in your Linux distribution.

Putting in NVM (Node Model Supervisor) in Linux

To put in or replace nvm in your Linux distribution, you’ll be able to obtain the auto-install script utilizing curl or wget command line instruments as proven.

# curl -o- https://uncooked.githubusercontent.com/nvm-sh/nvm/v0.39.3/set up.sh | bash
OR
# wget -qO- https://uncooked.githubusercontent.com/nvm-sh/nvm/v0.39.3/set up.sh | bash

The above auto-install script clones the nvm repository to ~/.nvm in your house listing and add the required supply instructions to your shell startup scripts i.e ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc, relying on the shell program you’re utilizing as proven within the following output.

Set up NVM in Linux

curl -o- https://uncooked.githubusercontent.com/nvm-sh/nvm/v0.39.3/set up.sh | bash
  % Whole    % Acquired % Xferd  Common Velocity   Time    Time     Time  Present
                                 Dload  Add   Whole   Spent    Left  Velocity
100 15916  100 15916    0     0  34227      0 --:--:-- --:--:-- --:--:-- 34301
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
distant: Enumerating objects: 359, finished.
distant: Counting objects: 100% (359/359), finished.
distant: Compressing objects: 100% (305/305), finished.
distant: Whole 359 (delta 40), reused 168 (delta 28), pack-reused 0
Receiving objects: 100% (359/359), 219.46 KiB | 6.86 MiB/s, finished.
Resolving deltas: 100% (40/40), finished.
* (HEAD indifferent at FETCH_HEAD)
  grasp
=> Compressing and cleansing up git repository

=> Appending nvm supply string to /root/.bashrc
=> Appending bash_completion supply string to /root/.bashrc
=> You at the moment have modules put in globally with `npm`. These will no
=> longer be linked to the energetic model of Node whenever you set up a brand new node
=> with `nvm`; and so they might (relying on the way you assemble your `$PATH`)
=> override the binaries of modules put in with `nvm`:
...

As soon as the set up is full, shut your present terminal window and open a brand new one Or, merely supply your shell profile file to load nvm. For instance, if you’re utilizing bash, run the next command:

$ supply ~/.bashrc
OR
$ supply ~/.profile

Subsequent, confirm if the nvm has been put in in your system utilizing the next command.

# command -v nvm

nvm

It should present output as ‘nvm‘ if the set up was profitable.

Set up A number of Node.js Variations Utilizing NVM

Now it’s time to learn to use Node Model Supervisor in Linux. To obtain, compile, and set up the newest launch of node, run the next command:

# nvm set up node 

Notice that within the above command, “node” is an alias for the newest model.

Set up Newest Node Model in Linux

Downloading and putting in node v20.0.0...
Downloading https://nodejs.org/dist/v20.0.0/node-v20.0.0-linux-x64.tar.xz...
########################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now utilizing node v20.0.0 (npm v9.6.4)
Creating default alias: default -> node (-> v20.0.0)

To put in a particular “node” model, first checklist the out there node variations after which set up the model as proven.

# nvm ls-remote
# nvm set up 19.0.0  

Set up Particular Node Model in Linux

Downloading and putting in node v19.0.0...
Downloading https://nodejs.org/dist/v19.0.0/node-v19.0.0-linux-x64.tar.xz...
########################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now utilizing node v19.0.0 (npm v8.19.2)

Upon getting put in a Node.js model utilizing nvm, the system ought to now level to the Node.js and npm variations beneath nvm. You may verify the situation of the node and npm binary/command being utilized by working the which command as follows:

# which node
/root/.nvm/variations/node/v20.0.0/bin/node

# which npm
/root/.nvm/variations/node/v20.0.0/bin/npm

# node -v
v20.0.0

# npm -v
9.6.4

Itemizing Put in Node.js Variations

You may verify all put in variations with the next command:

# nvm ls

Listing Put in Node Variations in Linux

->      v19.0.0
        v20.0.0
         system
default -> node (-> v20.0.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> secure (-> v20.0.0) (default)
secure -> 20.0 (-> v20.0.0) (default)
lts/* -> lts/hydrogen (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.0 (-> N/A)
lts/hydrogen -> v18.16.0 (-> N/A)

Select Node Model for a Mission

That is the place nvm turns into attention-grabbing. Now you need to use nvm to decide on the model of node.js to make use of for every venture you’re engaged on, based mostly on necessities. Let’s see how to do that, as defined under.

Open a number of terminals and transfer into the venture directories. For this information, we have now two tasks beneath ~/tasks/app-server and ~/tasks/test-ui that require node model 19.0.0 and 20.0.0 deceptively.

------------ Mission 1 ------------ 
$ cd ~/tasks/api-server
$ nvm use 19.0.0
$ node -v

------------ Mission 2 ------------
$ cd ~/tasks/test-ui
$ nvm use 20.0.0
$ node -v

Necessary: Notice that when switching between completely different variations of Node.js, any international npm packages that you’ve put in is not going to work. It is because the a number of Node.js model installations are fully impartial.

For instance, when you’ve got a world bundle put in when model 19.0.0 is energetic, whenever you swap to model 20.0.0, it’s worthwhile to reinstall the worldwide bundle beneath the brand new model.

Importantly, you’ll be able to view the trail to the executable to the place a particular node model was put in as follows:

# nvm which 20.0.0
# nvm which 19.0.0
# nvm which system  #verify system-installed model of a node utilizing “system” alias

Set Default Node.js Model in Linux

Moreover, to manually set a default node model for use in any new shell, use the alias “default” as proven.

# nvm alias default 20.0.0
# nvm alias default system
# nvm alias default 19.0.0

Notice: You may create a .nvmrc initialization file in your venture root listing (or any father or mother listing) and add a node model quantity or some other flags or utilization choices that nvm understands, in it. Then use among the instructions we have now simply checked out above to function with the desired model within the file.

Uninstalling Node.js Model in Linux

To uninstall or take away a model of Node.js, challenge the next command (don’t forget to interchange 19.0.0 with the model quantity):

# nvm uninstall 19.0.0

Uninstalling NVM in Linux

To take away nvm manually out of your system, run the next instructions:

# rm -rf "$NVM_DIR"
OR
# rm -rf ~/.nvm

Subsequent, edit ~/.bashrc (or the relevant shell profile config file, as listed above) and take away the next config strains:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This masses nvm
[[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion

For extra info, see nvm --help or go to the Node Model Supervisor Github repository: https://github.com/nvm-sh/nvm.

That’s all! Node Model Supervisor is an easy bash script to handle a number of energetic node.js variations in your Linux system. Use the suggestions type under to ask questions or share your feedback with us.

If You Respect What We Do Right here On TecMint, You Ought to Contemplate:

TecMint is the quickest rising and most trusted group web site for any type of Linux Articles, Guides and Books on the internet. Hundreds of thousands of individuals go to TecMint! to look or browse the 1000’s of printed articles out there FREELY to all.

If you happen to like what you’re studying, please think about shopping for us a espresso ( or 2 ) as a token of appreciation.

Support Us

We’re grateful to your by no means ending assist.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments