DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Error Handling Inside Kumologica Subflow
  • Deploy a Hyperledger Fabric v2 Web App Using the Node.js SDK
  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • 5 Best Node.js Practices to Develop Scalable and Robust Applications

Trending

  • How to Perform Custom Error Handling With ANTLR
  • How to Ensure Cross-Time Zone Data Integrity and Consistency in Global Data Pipelines
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  1. DZone
  2. Coding
  3. JavaScript
  4. How To Change Node.JS Version

How To Change Node.JS Version

Plag check clear. Let's look at how to change Node.JS version using NPM, and how to update old projects.

By 
Johnny Simpson user avatar
Johnny Simpson
DZone Core CORE ·
Mar. 20, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
4.5K Views

Join the DZone community and get the full member experience.

Join For Free

In this quick guide, we'll be looking at the easiest way to change the Node.JS version using nvm.

Using NVM To Change node.JS Version

First, you will need to install nvm, which stands for node version management. To install nvm, you can do it by running the following script:

Plain Text
 
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Alternatively, you can install it with wget:

Plain Text
 
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

After it is installed, you have to run the following command to start using it immediately - simply copy and paste this into your terminal and press enter to get going:

Plain Text
 
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

To test this has worked, write nvm into the terminal, and press enter. You should be greeted with the nvm help functions.

Changing Node.JS Version With NVM

To change Node.JS versions, we have to first download the version we want. Make sure you have nvm installed first. If you don't know the version you want to install, type nvm ls-remote to get a full list of all installable Node.JS versions.

Next, when you have selected the version you want to install, use nvm install to install it. The below code will install Node.JS v17.0.1:

Plain Text
 
nvm install 17.0.1

If you simply want to install the latest stable version of Node.JS, you can use the following command:

Plain Text
 
nvm install node

You can also use nvm install --lts instead!

Once the installation has finished, use the nvm use command to ensure the correct version is being used. The below code will ensure v17.0.1 is being used:

Plain Text
 
nvm use 17.0.1

As before, nvm use node or nvm use --lts will use the latest stable version. Now you have installed and changed your Node.JS version using nvm.

Upgrading an Old Project to a New Node.JS Version

If you have been stuck on an old version of Node.JS, your project may be dependent on old versions of packages. To fully upgrade your old package.json after changing the Node.JS version, you can use the npm package, npm-check-updates.

To install npm-check-updates, use the cd to move into the directory you want to upgrade. Then run the following command:

Plain Text
 
npx npm-check-updates

You will be asked to install npm-check-updates - type 'y' and then press enter.

After the installation is complete, you will be given a list of possible upgrades for your package.json. If you wish to proceed, run ncu -u to fully upgrade your package.json.

Now you will have changed the Node.JS version, and fully upgraded your old project with npm-check-updates.

Node.js Plain text

Published at DZone with permission of Johnny Simpson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Error Handling Inside Kumologica Subflow
  • Deploy a Hyperledger Fabric v2 Web App Using the Node.js SDK
  • While Performing Dependency Selection, I Avoid the Loss Of Sleep From Node.js Libraries' Dangers
  • 5 Best Node.js Practices to Develop Scalable and Robust Applications

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!