在Ubuntu上无需使用sudo安装NodeJS

12
我已经按照 node-and-npm-in-30-seconds.sh 的步骤操作了。

以前我使用Yeoman和bower创建AngularJS应用程序,需要使用NodeJS和sudo来进行所有安装。

这就是我所遵循的步骤。

sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

sudo apt-get install git-core

最近我尝试创建一个AngularJS应用程序,但它没有正常创建。然后我发现在安装nodejs、yeoman和Bower时不应该使用sudo。

我在这里node-and-npm-in-30-seconds.sh找到了解决方案。

所以我首先卸载了NodeJS。

sudo apt-get remove nodejs

然后选择了链接中提供的第一个选项

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
上一个命令没有起作用。它显示了:
$ curl https://www.npmjs.org/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    51  100    51    0     0     63      0 --:--:-- --:--:-- --:--:--    63
sh: 1: Moved: not found

我在谷歌上搜索并尝试了这个Stack Overflow答案中的以下内容

curl -O -L https://npmjs.org/install.sh
sh install.sh

它显示以下错误

npm cannot be installed without node.js.
Install node first, and then try again.

Maybe node is installed, but not in the PATH?
Note that running as sudo can change envs.

PATH=/home/myuser/local/bin:/usr/lib/jvm/java-7-oracle/bin:/usr/lib/jvm/java-7-oracle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
为什么会这样?我该如何解决呢?谢谢。
2个回答

14

好的,这个我尝试过并且对我有效

echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=$HOME/local
make install
curl -L https://www.npmjs.com/install.sh | sh

需要执行 sudo apt install python3-pippip3 install distutils,否则 ./configure --prefix=$HOME/local 将会失败。 - Fluchaa

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接