两个问题:
1.nodejs的安装
使用Mac OS X Binaries (.tar.gz)(64位)来安装:
http://www.nodejs.org/download/
安装参照:http://blog.snowinmay.net/?p=41
安装要点:
1.1把之前的nodejs文件都清理掉:
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1
1.2解压文件到自己喜欢的目录(最好是系统默认的程序安装目录,这样不用写环境变量)
我写的环境变量:export PATH="~/work/node/bin:$PATH"
我这次安装nodejs出现问题是因为在复制文件的时候把bin文件夹中的文件多复制了一层:
本来应该是这样的:
Prince-2:node snowinmay$ ls
ChangeLog README.md include share LICENSE bin lib
Prince-2:node snowinmay$ cd bin/
Prince-2:bin snowinmay$ ls
node npm
node和npm在bin中,我复制的时候把node和npm放在了bin/bin/下面,所以和环境变量对应不起来了。
2.npm的安装
npm的出错分两次,第一次是因为:curl https://npmjs.org/install.sh | sh 写错了,提示错误一直是:
directory sh: line 2: syntax error near unexpected token
<'
'h: line 2: `<head><title>301 Moved Permanently</title></head>
Prince-2:node snowinmay$ sudo npm install -g npmlog
正确的写法应该是:
curl -0 -L http://npmjs.org/install.sh | sudo sh
运行之后提示:
npm cannot be installed without nodejs.
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=~/work/node/bin:/Users/snowinmay/.rvm/gems/ruby-2.0.0-p451/bin:/Users/snowinmay/.rvm/gems/ruby-2.0.0-p451@global/bin:/Users/snowinmay/.rvm/rubies/ruby-2.0.0-p451/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/snowinmay/.rvm/bin
提示环境变量写错了,怪不得之前用:which node 和which npm都无效,看了一下环境变量文件:
export PATH="~/work/node/bin:$PATH" 改成了:
export PATH="$HOME/work/node/bin:$PATH"
Prince-2:bin snowinmay$ which node
/Users/snowinmay/work/node/bin/node
Prince-2:bin snowinmay$ which npm
/Users/snowinmay/work/node/bin/npm
Prince-2:bin snowinmay$ $PATH
-bash: /Users/snowinmay/work/node/bin:/Users/snowinmay/work/node/bin:~/work/node/bin:/Users/snowinmay/.rvm/gems/ruby-2.0.0-p451/bin:/Users/snowinmay/.rvm/gems/ruby-2.0.0-p451@global/bin:/Users/snowinmay/.rvm/rubies/ruby-2.0.0-p451/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/snowinmay/.rvm/bin:/Users/snowinmay/.rvm/bin:/Users/snowinmay/.rvm/bin: No such file or directory
运行:
Prince-2:~ snowinmay$ curl -0 -L http://npmjs.org/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 193 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 6711 100 6711 0 0 2324 0 0:00:02 0:00:02 --:--:-- 5386
tar=/usr/bin/tar
version:
bsdtar 2.8.3 - libarchive 2.8.3
install npm@latest
fetching: http://registry.npmjs.org/npm/-/npm-1.4.21.tgz
0.10.29
1.4.21
cleanup prefix=/Users/snowinmay/work/node
find: /Users/snowinmay/work/node/share/man: No such file or directory
find: /Users/snowinmay/work/node/share/man: No such file or directory
find: /Users/snowinmay/work/node/lib/node: No such file or directory
find: /Users/snowinmay/work/node/lib/node: No such file or directory
All clean!
> npm@1.4.21 prepublish .
> node bin/npm-cli.js prune --prefix=. --no-global && rm -rf test/*/*/node_modules && make -j8 doc
make: Nothing to be done for `doc'.
/Users/snowinmay/work/node/bin/npm -> /Users/snowinmay/work/node/lib/node_modules/npm/bin/npm-cli.js
npm@1.4.21 /Users/snowinmay/work/node/lib/node_modules/npm
It worked
问题结束
===================================
/etc/profile;/etc/bashrc 是针对系统所有用户的全局变量,只有root用户才能修改这两个文件,对一般用户来说是他们是只读的。一般用户要想修改它们,可以在命令前加sudo,意思是以Root身份执行,比如:sudo vi /etc/profile ,然后按照提示输入密码即可。
Prince-2:~ snowinmay$ vim .bash_profile
Prince-2:~ snowinmay$ source ~/.bash_profile
Prince-2:~ snowinmay$ $PATH
-bash: ~/work/node/bin:/Users/snowinmay/.rvm/gems/ruby-2.0.0-p451/bin:/Users/snowinmay/.rvm/gems/ruby-2.0.0-p451@global/bin:/Users/snowinmay/.rvm/rubies/ruby-2.0.0-p451/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/snowinmay/.rvm/bin:/Users/snowinmay/.rvm/bin: No such file or directory
但是npm还是不能用:
Prince-2:node snowinmay$ node -v
v0.10.29
Prince-2:node snowinmay$ npm -v
module.js:340
throw err;
^
Error: Cannot find module 'npmlog'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/snowinmay/work/node/bin/npm:19:11
at Object.<anonymous> (/Users/snowinmay/work/node/bin/npm:87:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
Prince-2:node snowinmay$
Prince-2:node snowinmay$
Prince-2:node snowinmay$ make install
make: * No rule to make target install'. Stop. Prince-2:node snowinmay$ curl https://npmjs.org/install.sh | sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 193 100 193 0 0 119 0 0:00:01 0:00:01 --:--:-- 153 sh: line 1: html: No such file or directory sh: line 2: syntax error near unexpected token
<'
'h: line 2: `<head><title>301 Moved Permanently</title></head>
Prince-2:node snowinmay$ sudo npm install -g npmlog
Password:
sudo: npm: command not found
Prince-2:node snowinmay$
Prince-2:node snowinmay$ which node
Prince-2:node snowinmay$ which npm