I installed nodejs 4 on Ubuntu 14.04 using node’s official PPA, as described here. It seems like npm v2 is the default so I upgraded npm to v3 using itself (
npm update --global
). Version 3 is required by the software I am deploying.Everything is fine until I run regular security updates etc. using
apt-get update
/upgrade
and npm gets consistently downgraded to v2.Is there any way to prevent npm global packages (specifically npm itself) being altered by apt-get?
Some config files in case useful:
# /etc/apt/sources.list deb http://mirrors.digitalocean.com/ubuntu trusty main restricted deb-src http://mirrors.digitalocean.com/ubuntu trusty main restricted deb http://mirrors.digitalocean.com/ubuntu trusty-updates main restricted deb-src http://mirrors.digitalocean.com/ubuntu trusty-updates main restricted deb http://mirrors.digitalocean.com/ubuntu trusty universe deb-src http://mirrors.digitalocean.com/ubuntu trusty universe deb http://mirrors.digitalocean.com/ubuntu trusty-updates universe deb-src http://mirrors.digitalocean.com/ubuntu trusty-updates universe deb http://mirrors.digitalocean.com/ubuntu trusty multiverse deb-src http://mirrors.digitalocean.com/ubuntu trusty multiverse deb http://mirrors.digitalocean.com/ubuntu trusty-updates multiverse deb-src http://mirrors.digitalocean.com/ubuntu trusty-updates multiverse deb http://mirrors.digitalocean.com/ubuntu trusty-backports main restricted universe multiverse deb-src http://mirrors.digitalocean.com/ubuntu trusty-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu trusty-security main deb-src http://security.ubuntu.com/ubuntu trusty-security main deb http://security.ubuntu.com/ubuntu trusty-security universe deb-src http://security.ubuntu.com/ubuntu trusty-security universe # /etc/apt/sources.list.d/nodesource.list deb https://deb.nodesource.com/node_4.x trusty main deb-src https://deb.nodesource.com/node_4.x trusty main
Answer
After a bit more searching I found this github thread which seems to suggest you are going to need to do some pinning. I suggest you try adding creating the file /etc/apt/preferences.d/nodejs
with the below contents as suggested in that issue.
Package: *
Pin: origin deb.nodesource.com
Pin-Priority: 1001
You can use the apt-cache policy nodejs
command before and after configuring pinning to verify that it changes the priorities.
Attribution
Source : Link , Question Author : contrebis , Answer Author : Zoredache