I'm using a Debian/Ubuntu based distribution (specifically, AWS Ubuntu 16.04) and trying to install NPM through apt-get
.
My Angular 2 application needs a higher version than 3.9.x of NPM, but the default version which is getting installed is 3.5.2 using sudo apt-get install npm
on AWS Ubuntu 16.04. I'm trying to update NPM, but it's not getting upgraded to 4.6.1 (latest) from 3.5.2.
How do I install/update NPM so that I've got the latest version?
type 'hash -r' on your server bash.
Then check your 'npm -v' again
You're getting version 3.5.2 of npm, because that's the version in the repositories . Debian and Ubuntu are typically terrible at keeping up with Node and npm's fast rate of development, so you'll often find the packages are out of date, and aren't much use to you.
Some Debian distributions (eg Jessie) only have npm v1.4.21 , which is even more out of date. Incidentally, Debian Jessie is the version upon which Raspbian Jessie, the RPi distribution, is based.
Instead, follow the instructions given on the Node.js website :
Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository (formerly Chris Lea's Launchpad PPA). Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.
NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros.
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs
Alternatively, for Node.js v7:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash - sudo apt-get install -y nodejs
The nodejs
package provided by NodeSource includes npm. Simply install that, and you'll be ready to go with the latest version.
Upgrade npm:
$ sudo npm install -g npm@latest
$ reboot
$ npm -v
Complete installation:
$ sudo apt install nodejs
$ sudo apt install npm
$ npm -v
npm version: 3.5.2
Then upgrade:
$ npm install -g npm@latest
$ reboot
$ npm -v
sudo npm install -g npm
对我有用,然后我需要@StefanBob 提供的答案
Try this
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
I've read this answer and it helped me on this issue:
https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation
I hope it helps you aswell.
$ sudo apt-get install npm
(...apt installation of npm was successful...)
$ npm -v
3.5.2
$ command -v npm
/usr/bin/npm
$ sudo npm install -g npm
(...npm installation of npm was successful...so far, so good)
After that, just restart the bash or follow krubo's steps.
@Nyakwar Dayo<\/a>的解决方案对我有用<\/a>。
sudo npm cache clean -f sudo npm install -gn sudo n stable<\/code><\/pre><\/blockquote>
但是 nodejs 包安装在不同的路径上,我手动删除了旧包(在
\/usr\/bin\/<\/code> )并添加了一个符号链接以指向新的包(在
\/usr\/local\/bin<\/code> )。
sudo rm \/usr\/bin\/node sudo ln -s \/usr\/local\/node \/usr\/bin\/node<\/code><\/pre>
这是运行命令的初始打印输出。
npm<\/code>版本从
5.8.0<\/code>更新到
8.1.2<\/code> 。但是即使在使用
hash -r<\/code>重新启动后,
nodejs<\/code>版本仍保持在
10.24.0<\/code> 。
"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.