How can I update NodeJS and NPM to the next versions?

后端 未结 30 2188
北荒
北荒 2020-11-22 08:07

I just installed Node.js and npm (for additional modules).

How can I update Node.js and the modules which I\'m using to the latest versions

30条回答
  •  面向向阳花
    2020-11-22 08:42

    I think the best way to manage node.js is to use NVM. NVM stands for Node Version Manager.

    It's a must-have tool for node.js developers!

    You can install NVM using the following command, open terminal and run any one of the following:-

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
    

    or

    wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
    

    After installing this it's recommended to close the current terminal and open a new one since NVM will be adding some environment variables so terminal needs to be restarted.

    I'll list down some of the basic commands for using NVM.

    • This will fetch all the node versions from the internet. All node versions from beginning till date will be shown, It will also mention LTS versions alongside.
    nvm ls-remote 
    
    • This will install the node version which you want (version list is obtained using the above command)
    nvm install v10.15.1
    
    • This command will give us the list of node versions that are installed locally
    nvm ls
    
    • This command is used to remove the node version that you want from your computer
    nvm uninstall v10.15.1
    
    • The following command will help you upgrade to the latest working npm on the current node version
    nvm install-latest-npm
    
    • NVM can be used to manage multiple node versions simultaneously
    • It can also help you install all the global npm packages from one version to another instead of manually installing each one of them!
    • There are many other uses of nvm the details of which and the commands can be found here Node Version Manager

提交回复
热议问题