在Debian/Ubuntu上安装Node.js(使用nvm)
动机
如果在Debian/Ubuntu上使用apt-get安装Node.js,命令的名称将成为nodejs。这样一来,npm和其他命令就无法运行。(在其他操作系统上,它安装的命令名称为node)
我看到很多使用Ubuntu的人陷入这个问题,并通过使用ln命令创建符号链接或者使用mv命令解决问题。
在这里,我们会使用nvm来安装Node.js。
如果使用nvm安装,Node.js将被安装在每个用户的主目录下,所以不需要成为root用户,也不需要sudo命令。
步骤 (bù
就像公式中所写的那样。 (Jiù suǒ xiě de .)
-
- 安装 Nvm
-
- 配置到.profile
- 使用 Nvm 下载 Node.js
指令
tamura@ubu $ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.18.0/install.sh | bash
=> Downloading nvm from git to '/home/tamura/.nvm'
=> Cloning into '/home/tamura/.nvm'...
remote: Counting objects: 2638, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 2638 (delta 6), reused 1 (delta 0)
Receiving objects: 100% (2638/2638), 505.22 KiB | 254.00 KiB/s, done.
Resolving deltas: 100% (1425/1425), done.
Checking connectivity... done.
Note: checking out 'v0.18.0'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 5f5eb47... v0.18.0
=> Appending source string to /home/tamura/.bashrc
=> Close and reopen your terminal to start using nvm
tamura@ubu $ echo "source ~/.nvm/nvm.sh" >> ~/.profile
在这里先登出一次,然后重新登录。或者在源码中加载nvm.sh文件。输入nvm命令,如果有反应就表示OK。
tamura@ubu $ nvm
Node Version Manager
Usage:
nvm help Show this message
nvm --version Print out the latest released version of nvm
nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available
nvm uninstall <version> Uninstall a version
nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available
nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>
nvm current Display currently activated version
nvm ls List installed versions
nvm ls <version> List versions matching a given description
nvm ls-remote List remote versions available for install
nvm deactivate Undo effects of NVM on current shell
nvm alias [<pattern>] Show all aliases beginning with <pattern>
nvm alias <name> <version> Set an alias named <name> pointing to <version>
nvm unalias <name> Deletes the alias named <name>
nvm copy-packages <version> Install global NPM packages contained in <version> to current version
nvm unload Unload NVM from shell
Example:
nvm install v0.10.24 Install a specific version number
nvm use 0.10 Use the latest available 0.10.x release
nvm run 0.10.24 myApp.js Run myApp.js using node v0.10.24
nvm alias default 0.10.24 Set default node version on a shell
Note:
to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders
不用放在気上,我試著安裝Node.js。
tamura@ubu $ nvm ls-remote
...
(省略)
...
v0.11.11
v0.11.12
v0.11.13
v0.11.14
我尝试安装版本为v0.11.14的软件。
tamura@ubu $ nvm install 0.11.14
--2014-11-09 18:29:30-- https://nodejs.org/dist/v0.11.14/node-v0.11.14-linux-x64.tar.gz
nodejs.org (nodejs.org) をDNSに問いあわせています... 165.225.133.150
nodejs.org (nodejs.org)|165.225.133.150|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 6675959 (6.4M) [application/octet-stream]
`/home/tamura/.nvm/bin/node-v0.11.14-linux-x64/node-v0.11.14-linux-x64.tar.gz' に保存中
100%[========================================>] 6,675,959 156KB/s 時間 12s
2014-11-09 18:29:42 (566 KB/s) - `/home/tamura/.nvm/bin/node-v0.11.14-linux-x64/node-v0.11.14-linux-x64.tar.gz' へ保存完了 [6675959/6675959]
Now using node v0.11.14
tamura@ubu $ node --version
v0.11.14
完成了。
总结
- Node.jsはnvmで入れましょう
请参考其他的Qiita等相关资料来了解nvm的使用方法。
请参照以下内容:
参考这个句子,请翻译成中文:
https://github.com/creationix/nvm可以被称为nvm的代码存储库。