在 Ubuntu 中不使用 sudo 安装 NodeJS [英] Installing NodeJS without sudo in Ubuntu

查看:30
本文介绍了在 Ubuntu 中不使用 sudo 安装 NodeJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经关注了 node-and-npm-in-30-seconds.sh.

之前我曾经使用 Yeoman 和 bower 和 NodeJS 创建 AngularJS 应用程序.那个时候我用 sudo 来安装所有的.

Earlier I used to create AngularJS application using Yeoman and bower with NodeJS. That time I used sudo to install all.

这是我关注的

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.

Recently I tried to create an AngularJS application, but it didn't create properly. Then I found I should not use sudo while installing nodejs, yeoman and Bower.

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

I searched and found the solution here node-and-npm-in-30-seconds.sh.

所以首先我卸载了 NodeJS

So first I uninstalled the 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

我从 this SO answer

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

为什么会这样?我该如何解决?谢谢.

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

这篇关于在 Ubuntu 中不使用 sudo 安装 NodeJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆