简体   繁体   English

如何安装 node.js

[英]How to install node.js

I did the following:我做了以下事情:

user@machine:~$ sudo n stable
   installed : v12.13.0 (with npm 6.12.0)
user@machine:~$ node --version
v8.10.0
user@machine:~$ which node
/usr/local/bin/node
user@machine:~$ /usr/local/bin/node --version
v12.13.0

I was expecting v12.13.0 to be installed, but node --version reveals v8.10.0.我期待安装 v12.13.0,但node --version显示 v8.10.0。

What did I do wrong?我做错了什么? How do I get v12.13.0 installed?如何安装 v12.13.0? FYI I am on Jetson Nano and I'm really just trying to get LTS Nodejs installed and don't know how.仅供参考,我在 Jetson Nano 上,我真的只是想安装 LTS Nodejs,但不知道如何安装。

BTW, if I do sudo apt-get install nodejs I only get v8.10.0.顺便说一句,如果我执行sudo apt-get install nodejs我只会得到 v8.10.0。

MORE INFO:更多信息:

user@machine:~$ node --version
v8.10.0
user@machine:~$ sudo node --version
v12.13.0

Seems sudo is affecting this somehow?似乎sudo以某种方式影响了这一点?

(I'm not very familiar with linux, but I'm learning... sorry if I'm missing "obvious" stuff.) (我对 linux 不是很熟悉,但我正在学习……抱歉,如果我遗漏了“明显”的东西。)

I worked around the problem by forgoing the use of n .我通过放弃使用n来解决这个问题。

Here's how to install directly from the dist at nodejs.org.这是直接从 nodejs.org 上的 dist 安装的方法。

wget https://nodejs.org/dist/v12.10.0/node-v12.13.0-linux-arm64.tar.gz
sudo tar -xf node-v12.13.0-linux-arm64.tar.gz --directory /usr/local --strip-components 1

It's very strange...这很奇怪……

Could you try something?你能试试吗?

mv /usr/local/bin/node /usr/local/bin/node.back
which node
mv /usr/local/bin/node.back /usr/local/bin/node

I just want to see what produce which if you remove the old node version binary.我只想看看如果你删除旧的节点版本二进制文件会产生which

Also provide more info about file /usr/local/bin/node , is it a symbolic link?还提供有关文件/usr/local/bin/node的更多信息,它是符号链接吗? If true, to what?如果是真的,是什么?

Can't comment but try replacing /usr/bin/node with a symbolic link to /usr/local/bin/node .无法评论,但尝试用 / /usr/local/bin/node /usr/bin/node Had similar issue some time ago that ate my brain.前段时间有类似的问题,吃了我的大脑。 Solved it like this.就这样解决了。

PS don't forget to backup PS别忘了备份

1) Try opening a new shell and checking what version of node you see there. 1)尝试打开一个新的 shell 并检查您在那里看到的节点版本。

n installs the node binary by default to /usr/local/bin/node . n默认情况下将节点二进制文件安装到/usr/local/bin/node You may already have had a node binary installed to /usr/bin/node , and your shell cache of known commands (paths) may be running the old one.您可能已经将节点二进制文件安装到/usr/bin/node ,并且已知命令(路径)的 shell 缓存可能正在运行旧的。

Example of problem with bash: https://github.com/tj/n/issues/588 bash 问题示例: https://github.com/tj/n/issues/588

2) If your OS has the command, you can run which -a node to see if you have multiple versions and where they are installed. 2)如果您的操作系统有该命令,您可以运行which -a node以查看您是否有多个版本以及它们的安装位置。 (Uninstalling the ones you don't want reduces potential for confusion.) (卸载您不想要的可以减少混淆的可能性。)

3) Check the location of the intended version is in your PATH. 3) 检查预期版本的位置是否在您的 PATH 中。 If you are using n , try running n doctor .如果您正在使用n ,请尝试运行n doctor There are some extra checks that the version of node found is the one that is the one that n installed.有一些额外的检查来确定找到的节点版本是n安装的那个版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM