为此我已经工作了一个小时。
摘自他们的官方文件:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
但是,它对我来说从来都不起作用。我尝试过清除npm cache
,甚至卸载它并再次运行这两个命令。它仍然不起作用。我不断收到版本0.10.25
我跑:
grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/*
这就是我得到的:
deb http://id.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty main restricted
deb http://id.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb http://id.archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty universe
deb http://id.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb http://id.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://id.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb http://id.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://id.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
deb http://extras.ubuntu.com/ubuntu trusty main
deb-src http://extras.ubuntu.com/ubuntu trusty main
deb http://ppa.launchpad.net/cpug-devs/ppa/ubuntu saucy main
deb http://ppa.launchpad.net/cwchien/gradle/ubuntu saucy main
deb http://ppa.launchpad.net/dominik-stadler/subversion-1.7/ubuntu trusty main
deb http://ppa.launchpad.net/dominik-stadler/subversion-1.7/ubuntu trusty main
deb http://ppa.launchpad.net/dominik-stadler/subversion-1.8/ubuntu trusty main
deb http://linux.dropbox.com/ubuntu saucy main
deb http://dl.google.com/linux/chrome/deb/ stable main
deb http://dl.google.com/linux/chrome/deb/ stable main
deb http://dl.google.com/linux/chrome/deb/ stable main
deb http://ppa.launchpad.net/plushuang-tw/uget-stable/ubuntu saucy main
deb [arch=amd64,i386] http://repo.steampowered.com/steam/ precise steam
deb-src [arch=amd64,i386] http://repo.steampowered.com/steam/ precise steam
deb [arch=amd64,i386] http://repo.steampowered.com/steam/ precise steam
deb-src [arch=amd64,i386] http://repo.steampowered.com/steam/ precise steam
deb http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu trusty main
deb http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu trusty main
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
看来nodejs
不在名单上。
我该怎么办?请帮帮我
答案1
以下是从源代码安装 Node.js 的步骤(OSX/linux)
注意 - 这将安装 Node.js,为您提供节点和 npm,它们在每个版本中一起提供。
要重新开始,请删除先前的节点和 npm 安装以及这些:
sudo mv ~/.npmrc ~/.npmrc_ignore
sudo mv ~/.npm ~/.npm_ignore
sudo mv ~/tmp ~/tmp_ignore
sudo mv ~/.npm-init.js ~/.npm-init.js_ignore
下载源代码自:http://nodejs.org/download/
cd node-v5.0.0 # <-- or whatever download expands to
你可以/应该以你自己的身份而不是 root (sudo) 发出以下所有命令
选择以下 NODE_PARENT 位置之一来定义节点的安装位置:
# export NODE_PARENT=/some/desired/install/path_goes_here
# export NODE_PARENT=/usr/local/bin/nodejs # use this ONLY if you MUST install as root (sudo)
export NODE_PARENT=${HOME}/node-v5.0.0 # Recommended - owned by you NOT root
export PATH=${NODE_PARENT}/bin:${PATH} # jack up PATH for executables
export NODE_PATH=${NODE_PARENT}/lib/node_modules # so node itself can find its modules dir
./configure --prefix=${NODE_PARENT}
make
make install
将其放入上面 --prefix 定义的目录中
当您使用语法: npm install -g some_cool_module 时,全局的 -g 会将其安装到目录 $NODE_PATH 而不是您的 $PWD
重要提示 - 将以上三个 export xxx=yyy 命令放入你的 ~/.bashrc 或类似命令中,以保留这些环境变量更改
在后续更新 Nodejs 时,只需在 NODE_PARENT 环境变量中使用新版本名称更新 ~/.bashrc ,然后获取此 ~/.bashrc 并简单地发出上述 configure/make/install
如果您之前安装了节点,您可能需要将之前安装的模块复制到新位置:
~/node-v5.0.0/lib/node_modules/
或者使用 npm install -g xxxx 进行新模块安装
答案2
我最终使用了非官方/过时的方式:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node
取自 :
但是这会导致我的node -v
和我的nodejs -v
版本不同。nodejs -v
仍然返回过时的版本。我不知道这是否有任何影响。