why I can't install specific version of npm and how to do it?

10,026

If you want to use npm to install npm, you need to use the -g flag to signal that the package should be installed globally. If you install without the -g flag, it will try to find a package.json file in the local directory.

sudo npm install -g [email protected] 

btw, you cannot install nodejs with npm. To manage nodejs versions, you can use either nvm or n. I recommend using n

Share:
10,026

Related videos on Youtube

Mojtaba Arvin
Author by

Mojtaba Arvin

Updated on June 04, 2022

Comments

  • Mojtaba Arvin
    Mojtaba Arvin almost 2 years

    My linux distribution is :

    $ uname -a
    Linux 16.04.2-Ubuntu
    

    Also ,my npm version was :

    $ npm -v
    3.5.2
    

    I wanted to install version 3.10.10 of npm via this command :

    $ sudo npm cache clean -f
    $ sudo npm install [email protected]
    

    but I get these errors :

    npm WARN enoent ENOENT: no such file or directory, open '/home/arvin/package.json'
    npm WARN myname No description
    npm WARN myname No repository field.
    npm WARN myname No README data
    npm WARN myname No license field.
    

    and when use same command for install version 6.12.2 of nodejs :

    $ sudo npm install [email protected]
    

    and I get these errors :

    npm ERR! Linux 4.13.0-26-generic
    npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "[email protected]"
    npm ERR! node v4.2.6
    npm ERR! npm  v3.5.2
    npm ERR! No compatible version found: [email protected]
    npm ERR! Valid install targets:
    npm ERR! 0.0.0
    npm ERR! 
    npm ERR! 
    npm ERR! If you need help, you may report this error at:
    npm ERR!     <https://github.com/npm/npm/issues>
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     /home/arvin/npm-debug.log
    

    finally , I decided to completely remove npm' andnodejs` via this commands :

    $ sudo apt-get purge --auto-remove nodejs
    $ sudo apt autoremove
    $ sudo rm -R ~/.npm
    $ sudo rm /usr/local/bin/npm, /usr/local/share/man/man1/node, /usr/local/lib/dtrace/node.d, ~/.node-gyp, /opt/local/bin/node, opt/local/include/node, /opt/local/lib/node_modules
    $ sudo npm uninstall npm
    

    So , how can I install npm v3.10.10 and nodejs v6.12.2 in ubuntu 16.04 ?

    • Simon Cooper
      Simon Cooper about 6 years
      Have you tried installing node first and then npm?
  • Pubudu Dodangoda
    Pubudu Dodangoda over 5 years
    @Unkas This is with the assumption that npm is already installed and just want to change the version. To install npm for the first time, you need to install NodeJs first.