Node Model Supervisor (NVM briefly) is an easy bash script to handle a number of lively node.js variations in your Linux system. It lets you set up a number of node.js variations, and examine all variations out there for set up and all put in variations in your system.
Nvm additionally helps operating of a selected node.js model and it may well present the trail to the executable to the place it was put in, and rather more.
On this article, we’ll clarify learn how to set up Node Model Supervisor (NVM) to handle a number of lively 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 might be 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, achieved. distant: Counting objects: 100% (359/359), achieved. distant: Compressing objects: 100% (305/305), achieved. distant: Whole 359 (delta 40), reused 168 (delta 28), pack-reused 0 Receiving objects: 100% (359/359), 219.46 KiB | 6.86 MiB/s, achieved. Resolving deltas: 100% (40/40), achieved. * (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 presently have modules put in globally with `npm`. These will no => longer be linked to the lively model of Node if you set up a brand new node => with `nvm`; they usually could (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 can 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 discover ways to use Node Model Supervisor in Linux. To obtain, compile, and set up the most recent launch of node, run the next command:
# nvm set up node
Word that within the above command, “node” is an alias for the most recent 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 selected “node” model, first listing 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)
After getting put in a Node.js model utilizing nvm, the system ought to now level to the Node.js and npm variations below nvm. You’ll be able to examine the situation of the node and npm binary/command being utilized by operating 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’ll be able to examine all put in variations with the next command:
# nvm ls
Checklist 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 Venture
That is the place nvm turns into attention-grabbing. Now you should use nvm to decide on the model of node.js to make use of for every challenge you might be engaged on, primarily based on necessities. Let’s see how to do that, as defined beneath.
Open a number of terminals and transfer into the challenge directories. For this information, we’ve two tasks below ~/tasks/app-server
and ~/tasks/test-ui
that require node model 19.0.0 and 20.0.0 deceptively.
------------ Venture 1 ------------ $ cd ~/tasks/api-server $ nvm use 19.0.0 $ node -v ------------ Venture 2 ------------ $ cd ~/tasks/test-ui $ nvm use 20.0.0 $ node -v
Necessary: Word that when switching between totally different variations of Node.js, any world npm packages that you’ve got put in is not going to work. It’s because the a number of Node.js model installations are fully impartial.
For instance, in case you have a worldwide package deal put in when model 19.0.0 is lively, if you swap to model 20.0.0, you have to reinstall the worldwide package deal below the brand new model.
Importantly, you’ll be able to view the trail to the executable to the place a selected node model was put in as follows:
# nvm which 20.0.0 # nvm which 19.0.0 # nvm which system #examine 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
Word: You’ll be able to create a .nvmrc
initialization file in your challenge root listing (or any mum or dad listing) and add a node model quantity or some other flags or utilization choices that nvm understands, in it. Then use a number of the instructions we’ve 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, problem 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 traces:
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This hundreds nvm [[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion
For extra data, 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 lively node.js variations in your Linux system. Use the suggestions kind beneath to ask questions or share your feedback with us.
If You Recognize What We Do Right here On TecMint, You Ought to Contemplate:
TecMint is the quickest rising and most trusted neighborhood website for any type of Linux Articles, Guides and Books on the internet. Thousands and thousands of individuals go to TecMint! to go looking or browse the hundreds of printed articles out there FREELY to all.
In case you like what you might be studying, please take into account shopping for us a espresso ( or 2 ) as a token of appreciation.
We’re grateful to your by no means ending assist.