简体   繁体   English

在Ubuntu中安装没有sudo的NodeJS

[英]Installing NodeJS without sudo in Ubuntu

I have already followed node-and-npm-in-30-seconds.sh . 我已经关注了node-and-npm-in-30-seconds.sh

Earlier I used to create AngularJS application using Yeoman and bower with NodeJS. 之前我曾经使用Yeoman和bower与NodeJS创建AngularJS应用程序。 That time I used sudo to install all. 那次我用sudo来安装所有。

This is what I followed 这就是我所遵循的

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

Recently I tried to create an AngularJS application, but it didn't create properly. 最近我尝试创建一个AngularJS应用程序,但它没有正确创建。 Then I found I should not use sudo while installing nodejs, yeoman and Bower. 然后我发现在安装nodejs,yeoman和Bower时我不应该使用sudo。

I searched and found the solution here node-and-npm-in-30-seconds.sh . 我在这里搜索并找到了解决方案node-and-npm-in-30-seconds.sh

So first I uninstalled the NodeJS 所以首先我卸载了NodeJS

sudo apt-get remove nodejs

Then followed the first option provided in the link 然后按照链接中提供的第一个选项进行操作

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

The last command didn't work. 最后一个命令不起作用。 It showed 这显示了

$ 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

I googled and tried the following from this SO answer 我用谷歌搜索并尝试了以下SO答案

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

It is showing the following error 它显示以下错误

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

Why is it so? 为什么会这样? And how can I resolve it? 我该如何解决? Thanks. 谢谢。

Ok this I have tried and worked for me 好的,我已经尝试过并为我工作过

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

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

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