兩個問題:html
1.nodejs的安裝node
使用Mac OS X Binaries (.tar.gz)(64位)來安裝:mysql
http://www.nodejs.org/download/sql
安裝參照:http://blog.snowinmay.net/?p=41shell
安裝要點:npm
1.1把以前的nodejs文件都清理掉:vim
rm -r bin/node bin/node-waf include/node lib/node lib/pkgconfig/nodejs.pc share/man/man1/node.1ruby
1.2解壓文件到本身喜歡的目錄(最好是系統默認的程序安裝目錄,這樣不用寫環境變量)bash
我寫的環境變量:export PATH="~/work/node/bin:$PATH"curl
我此次安裝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 npmlogPassword:sudo: npm: command not foundPrince-2:node snowinmay$Prince-2:node snowinmay$ which nodePrince-2:node snowinmay$ which npm