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

后端 未结 30 1699
北荒
北荒 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:40

    Just with this code

    npm install update
    
    0 讨论(0)
  • 2020-11-22 08:41

    To update npm :

    npm install npm@{version} -g
    

    to update npm to the latest version:

    npm install npm@latest -g
    

    and to check the version :

    npm -v
    

    to update node js :

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n stable
    

    to check :

    node -v
    
    0 讨论(0)
  • 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
    0 讨论(0)
  • 2020-11-22 08:43

    When it comes to Linux I suggest an Update Node Using a Package Manager:

    Node comes with npm pre-installed, but the manager is updated more frequently than Node. Run npm -v to see which version you have, then npm install npm@latest -g to install the newest npm update. Run npm -v again if you want to make sure npm updated correctly.

    To update NodeJS, you’ll need npm’s handy n module. Run this code to clear npm’s cache, install n, and install the latest stable version of Node:

    sudo npm cache clean -f
    sudo npm install -g n
    sudo n stable
    

    To install the latest release, use n latest. Alternatively, you can run n #.#.# to get a specific Node version.


    When it comes to Windows/ macOS I suggest using Installers on Nodejs.org

    The Node.js downloads page includes binary packages for Windows and macOS — but why make your life more difficult? The pre-made installers — .msi for Windows and .pkg for macOS — make the installation process unbelievably efficient and understandable. Download and run the file, and let the installation wizard take care of the rest. With each downloaded update, the newer versions of Node and npm will replace the older version.

    Alternatively, macOS users can use the npm and n instructions above.


    When it comes to updating your node_modules dependencies folder, I suggest skipping all the things that could cause you a headache and just go to your specific project and re-run npm install again.

    Before anyone does that, I suggest first checking your package.json file for the following:

    As a user of NodeJS packages, you can specify which kinds of updates your app can accept in the package.json file. For example, if you were starting with a package version 1.0.4, this is how you could specify the allowed update version ranges in three basic ways:

    To Allow Patch Releases: 1.0 or 1.0.x or ~1.0.4
    To Allow Minor Releases: 1 or 1.x or ^1.0.4
    To Allow Major Releases: * or x

    Explanation:

    MAJOR version for when there are incompatible API changes. --> ~

    MINOR version for when functionality is added in a backwards compatible manner. --> ^

    PATCH version for when backward compatible bug fixes are done. --> *

    0 讨论(0)
  • 2020-11-22 08:45

    for nodejs should uninstall it and download your favorite version from nodejs.org for npm run below line in cmd:

    npm i npm
    
    0 讨论(0)
  • 2020-11-22 08:47

    I understand this question is for Linux machine but just in case anybody is looking for a Windows solution, just go to the Node.js site, click the download button on the homepage and execute the installer program.

    Thankfully it took care of everything and with a few clicks of 'Next' button I got the latest 0.8.15 Node.js version running on my Windows 7 machine.

    0 讨论(0)
提交回复
热议问题