çµå±ã®ã¨ãã node.js ããµã¼ãã¼ã«ã¤ã³ã¹ãã¼ã«ããã«ã¯ã©ãããã°ããã®ãï¼
以åãnvm ãå©ç¨ã㦠node.js ãã»ããã¢ããããè¨äºãæ¸ãã¾ãã
ã§ãããnvm ã¯ããã¾ã§éçºç¨ã®ç°å¢ãã»ããã¢ããããããã®ãã®ãªã®ã§ãµã¼ãã¼ä¸ã« node.js ãã¤ã³ã¹ãã¼ã«ããã®ã«ã¯åãã¦ã¾ãã
å ¬å¼ãµã¤ãã«ã¯å ·ä½çãªã¤ã³ã¹ãã¼ã«æ¹æ³ã¯æ¸ããã¦ãããããã«ãæ¸ã¿ãã¤ããªãé å¸ããã¦ãã¾ã
ããããã¦ã³ãã¼ããã¦ã㦠/usr/bin ã¨ã /usr/sbin ã«é ç½®ããã°ããã§ã¤ã³ã¹ãã¼ã«å®äºãªãã§ãããç¿æ £çã«ã©ããããã¦ããã®ããç¥ãããã§ããã
ã§ããã°ä½ããã®ããã±ã¼ã¸ããã¼ã¸ã£ã¼ãå©ç¨ããæ¹æ³ãããã¯ãã§ãã yum ã®ãªãã¸ããªã§æä¾ããã¦ãããã¼ã¸ã§ã³ã¯ããªãå¤ããã®æç¹ã®ææ°çãé
ä¿¡ããã¦ããªãããã§ãã
ãã㧠Production ãæèããç°å¢ãæ§ç¯ããéã«ãã©ãããã°ãæ軽ãã¤ããæãã« node.js ãã¤ã³ã¹ãã¼ã«ã§ãããã調ã¹ã¾ãã
ãã®è¨äºã§ã¯
1. ãããã1çªå¦¥å½ãªæ¹æ³
2. n ã³ãã³ãã®ä½¿ãæ¹
3. nvm 㨠n ã®éã
4. ã¾ã¨ã
ã«ã¤ãã¦èª¬æãã¾ã
1. ãããã1çªå¦¥å½ãªæ¹æ³
ã°ã°ã£ã¦ã¿ãã¨ãnode.js ããµã¼ãã¼ã«ã¤ã³ã¹ãã¼ã«ããã«ã¯ä»¥ä¸ã®3ãã¿ã¼ã³ã®æ¹æ³ãããå©ç¨ããã¦ããæ¹æ³ã£ã½ããã¨ãåããã¾ãã
- ã½ã¼ã¹ããã³ã³ãã«ãã
- ãã«ãæ¸ã¿ãã¤ããªããã¦ã³ãã¼ããã¦ãã¦ä»»æã®ãã£ã¬ã¯ããªã«é ç½®
- n ã³ãã³ããå©ç¨ãã¦ã¤ã³ã¹ãã¼ã«
ã½ã¼ã¹ããã³ã³ãã¤ã«ä»¥å¤ã®æ¹æ³ã§ããã°ãã£ã¦ãããã¨ã¯å®è³ªåããªã®ã§ãã¾ãå·®ã¯ãªããã§ãããn ã³ãã³ããå©ç¨ããã¤ã³ã¹ãã¼ã«ãä¸çªç°¡åããã ã£ãã®ã§æããç¾æç¹ã§ã¯ããã1çªå¦¥å½ãªæ¹æ³ã§ã
ãã®æ¹æ³ã¯ Carbon Five ã¨ããéçºä¼ç¤¾ã®ããã°è¨äºã«æ¸ããã¦ãã¾ãã
n ã³ãã³ããå©ç¨ãã node.js ã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¯ä»¥ä¸ã§ã
yum install nodejs npm --enablerepo=epel npm install -g n n stable
n ã³ãã³ã㯠nvm ã¨ä¼¼ããã㪠node.js ã®ãã¼ã¸ã§ã³ç®¡çãè¡ã£ã¦ãããã³ãã³ãã§ã
GitHub - tj/n: Node version management
nvm ã¯ãµã¼ãã¼ã®æ§ç¯ã«åãã¦ãªãã¨è¨ãã¾ããããn ã³ãã³ãã¯æ¹å¼ãç°ãªã£ã¦ããã®ã§ãµã¼ãã¼ã¸ã®ã¤ã³ã¹ãã¼ã«ã§ãåé¡ãªãå©ç¨ã§ãããã§ã
ããã«ã¤ãã¦ã¯å¾ã®æ¹ã§èª¬æãã¾ã
ã¡ãªã¿ã«ãæè¿å人çã«ãããã¤ã¤ãã ansible 㧠n ã³ãã³ããå©ç¨ãã node.js ã®ã¤ã³ã¹ãã¼ã«ãæ¸ãã¨ãããªãã¾ã
github.com
2. n ã³ãã³ãã®ä½¿ãæ¹
n ã³ãã³ãã®å©ç¨æ¹æ³ããã£ã¨èª¬æãã¾ã
node.js ãã¤ã³ã¹ãã¼ã«ããããã«ä½¿ãã ããªã®ã§ãã¼ã¸ã§ã³ã®ä¸è¦§è¡¨ç¤ºã¨ãã¼ã¸ã§ã³ã®åãæ¿ãã使ããã°ååã§ã
å©ç¨ã§ãããã¼ã¸ã§ã³ã®ä¸è¦§è¡¨ç¤º
$ n ls
0.8.6
0.8.7
ã çç¥ ã
0.12.6
ο 0.12.7
æå¹ã«ãªã£ã¦ãããã¼ã¸ã§ã³çªå·ã®å·¦ã«Î¿ã表示ããã¾ã
ææ°å®å®çãã¤ã³ã¹ãã¼ã«
$ n stable install : node-v0.12.7 mkdir : /usr/local/n/versions/node/0.12.7 fetch : https://nodejs.org/dist/v0.12.7/node-v0.12.7-linux-x64.tar.gz installed : v0.12.7
å
¬å¼ãµã¤ããã対å¿ãããã¼ã¸ã§ã³ã®ãã¤ããªããã¦ã³ãã¼ããã¦ãã¦é
ç½®ããã¾ã
æå®ãããã¼ã¸ã§ã³ã¸ã®åãæ¿ã
$ n 0.10.40 install : node-v0.10.40 mkdir : /usr/local/n/versions/node/0.10.40 fetch : https://nodejs.org/dist/v0.10.40/node-v0.10.40-linux-x64.tar.gz installed : v0.10.40
æ¢ã«ãã¤ããªããã¦ã³ãã¼ãæ¸ã¿ã§ããã°ãã¼ã¸ã§ã³ã®åãæ¿ãã®ã¿å®æ½ããã¾ã
3. nvm 㨠n ã®éã
nvm ã®ä»çµã¿
nvm ã®ä»çµã¿ã調ã¹ã¦ã¿ãã¨ãããnode ã³ãã³ãã®åãå
ãæå¹ã«ããã node.js ã®ãã¼ã¸ã§ã³ã«åãããã«ç°å¢å¤æ°ãæ¸ãæããä»çµã¿ã«ãªã£ã¦ãã¾ãã
nvm ã®ã³ãã³ããããã¦ã³ãã¼ããã¦ãã node.js ã®ãã¤ããªã¯å
¨ã¦å®è¡ããã¦ã¼ã¶ã¼ã®ãã¼ã ãã£ã¬ã¯ããªã«ç½®ããã¾ã
node.js ã®ã¤ã³ã¹ãã¼ã«ããã¼ã¸ã§ã³ã®åãæ¿ããè¡ã£ã¦ããå½±é¿ãããã®ã¯å®è¡ã¦ã¼ã¶ã¼ã®é åã®ã¿ãªã®ã§ ãã®ãµã¼ãã¼å
ã®ã°ãã¼ãã«ãªé åã«ã¯å½±é¿ããªãã¨ãããã¨ãç¹å¾´ã§ã
ã§ãããnode.js ã¸ã®ãã¹ã¯å®è¡ã¦ã¼ã¶ã¼ã®ç°å¢å¤æ°ã«ãã£ã¤ãä¾åãã¦ã¾ããããã¼ã¢ã³ã¨ãã¦åããã«ã¯ä½¿ãã¥ããããªå°è±¡ãåãã¾ã
$ which node /Users/chanmoro/.nvm/versions/node/v0.12.2/bin/node
nvm install å®è¡ãã㨠node.js ã®å ¬å¼ãµã¤ããã該å½ãã¼ã¸ã§ã³ã®ãã¤ããªããã¦ã³ãã¼ããã¦ãã¦ãPATH ã®å 容ãæ¸ãæãããã¾ã
$ echo $PATH /Users/chanmoro/.nvm/versions/node/v0.12.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin $ nvm install 0.12 ######################################################################## 100.0% Now using node v0.12.7 $ echo $PATH /Users/chanmoro/.nvm/versions/node/v0.12.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin $ which node /Users/chanmoro/.nvm/versions/node/v0.12.7/bin/node
nvm use ã§ãã¼ã¸ã§ã³ãåãæ¿ããå ´åã§ã install ã¨åæ§ã« PATH ã®å
容ãæ¸ãæãããã¾ã
n ã³ãã³ãã®ä»çµã¿
n ã³ãã³ã㯠nvm ã¨åæ§ã« node.js ã®å
¬å¼ãµã¤ããããã«ãæ¸ã¿ã®ãã¤ããªããã¦ã³ãã¼ããã¦ãã¾ã
ããã¦ãæå¹ã«ãããã¼ã¸ã§ã³ã®ãã¤ããªã /usr/local/bin ã«ã³ãã¼ããä»çµã¿ã«ãªã£ã¦ãã¾ã
ãªã®ã§ãn ã³ãã³ãã®å ´åã¯ãã®ãµã¼ãã¼å
ã®ã°ãã¼ãã«ãªé å(/usr/local/binã¨ã)ã«ã¢ã¸ã¥ã¼ã«ãé
ç½®ããã¾ã
æåã§ã®ã¤ã³ã¹ãã¼ã«æ¹æ³ã¨ã»ã¼åããã¨ããã£ã¦ããããã¼ã ãã£ã¬ã¯ããªé
ä¸ã«ãã¤ããªãç½®ãã®ã§ããªããç¹å®ã¦ã¼ã¶ã¼ã®ã¿ã«æå¹ãªç°å¢å¤æ°ãå©ç¨ããããã§ããªãã®ã§ãããªãããæãã§ãã
$ which node /usr/local/bin/node $ node --version v0.12.7 $ n 0.10 install : node-v0.10.40 mkdir : /usr/local/n/versions/node/0.10.40 fetch : https://nodejs.org/dist/v0.10.40/node-v0.10.40-linux-x64.tar.gz installed : v0.10.40 $ node --version v0.10.40 $ which node /usr/local/bin/node
nvm ã¯ã¦ã¼ã¶ã¼ã®ã¿ã«å½±é¿ã®ããé åã ãã§å®ç¾ãã¦ããã®ã«å¯¾ããn ã¯ãµã¼ãã¼å
ã®ã°ãã¼ãã«ãªé åã使ã£ã¦ããã¨ããç¹ã大ãããã¨ãªãã¾ã
ãã®ãã¨ããã nvm ã¯ããã¾ã§éçºç¨ã®ãã¼ã«ã§ãããã¨ãåããã¨æãã¾ã
ãªã®ã§ããµã¼ãã¼ãã»ããã¢ããããã¨ããç¹ã§ã¯ nvm ãã n ã®æ¹ããã妥å½ã¨ãããã¨ã«ã¯ãªãã¾ã
Production ç°å¢ã« node.js ã®ãã¼ã¸ã§ã³ç®¡çãå¿
è¦ãã¯å¥ã¨ãã¦
â»ãã¤ããªè½ã¨ãã¦ãã¦ç½®ãã ããªã®ã«å¤§ããããããã¨ããæãã¯ããã¾ããã»ã»ã»
4. ã¾ã¨ã
å ã»ã©ç´¹ä»ãã Carbon Five ã®ããã°è¨äºã§ã¯ãnode.js ãå©ç¨ããå ´åã®ãµã¼ãã¼æ§æã node.js ã¢ããªã®ãããã¤æ¹æ³ãªã©ãããªãå®è·µçãªå 容ãæ¸ããã¦ããã®ã§åèã«ãªãã¨æãã¾ã
node.js ã¯ã¡ãã£ã¨åã«ã±ã³ã«ãã¦ãã©ã¼ã¯ãã io.js ãçã¾ããããã¦ã¾ãã
ãã®å¾ã³ã¢ã¡ã³ãã¼ãä¸é¨æããããã£ãããã§ãããä»ã¯ä»²ç´ãããããã§ä»å¾ node.js ã«çµ±åããã¨ãã§ãªããªã大å¤ãããªç¶æ³ã£ã½ãã§ã
javascript ç¹æã®æ©æ§ãããããã¨ããã®ã§ node.js ãã¬ã³ã¨ãã®è©±ãããã¿ããã§ããã使ãã©ãããééããªããã°åã¨ãã¦ã¯ WebAPI ãã©ã¤ããªã¢ããªã±ã¼ã·ã§ã³ãã¤ããã®ã« node.js ã¯ããæãã ã¨æã£ã¦ããã®ã§ä»å¾ãé å¼µã£ã¦ãã£ã¦æ¬²ããã¨æã£ã¦ã¾ã
ä»åã¯ãã㪠node.js ã«ã¤ãã¦ã®è¨äºã§ãã