查看完整版本: 如何在 CentOS 7 使用 nvm 安裝 nodejs 9.4 與 npm 5.6


cuteftp 2018-1-29 08:46

如何在 CentOS 7 使用 nvm 安裝 nodejs 9.4 與 npm 5.6

node.js是一個完全獨立的程式環境,完全不依賴其他伺服器,這對於熟悉php、.net這些環境的開發者,可能會有點陌生。不過也因為這樣,開發者可以完全掌控整個伺服器的運作過程,也可以激發很多創意。<br><br>目前node.js 已經可以發佈到 9.4.0 , 如果要使用最新的版本...可以這樣做<br><br>Install Nodejs using NVM(建議這種方式)<br><br>(1)To install nvm, run the following command:<br># <font color="Red">curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash</font><br><br>The above command will clone the nvm repository to ~/.nvm and add the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).<br><br>因為有寫入.bashrc 等PATH , 所以使用前需要 Restart your Terminal once before start using NVM.<br><br>To verify whether NVM is installed or not, run:<br># command -v nvm<br><br>Sample output:<br>nvm<br><br>Now, we can install Nodejs and npm.<br><br>First, run the following command to view the list of available Nodejs versions:<br><br># nvm ls-remote<br><br>Sample output:<br>[...]<br> v8.8.1<br> v8.9.0 (LTS: Carbon)<br> v8.9.1 (LTS: Carbon)<br> v8.9.2 (LTS: Carbon)<br> v8.9.3 (LTS: Carbon)<br> v8.9.4 (Latest LTS: Carbon)<br> v9.0.0<br> v9.1.0<br> v9.2.0<br> v9.2.1<br> v9.3.0<br> v9.4.0<br><br>To install/update to the most recent Nodejs version, just run:<br><br>$ <font color="Teal">nvm install node</font><br><br>Alternatively, you can run the following to install any Nodejs version of your choice.<br><br>For example, to install Nodejs v9.3.0, run:<br><br># <font color="DarkGreen">nvm install v9.3.0</font><br>[quote]<br>Sample output:<br><br>Downloading and installing node v9.3.0...<br>Downloading https://nodejs.org/dist/v9.3.0/node-v9.3.0-linux-x64.tar.xz...<br>######################################################################## 100.0%<br>Computing checksum with sha256sum<br>Checksums matched!<br>Now using node v9.3.0 (npm v5.6.0)<br>Creating default alias: default -&gt; v9.3.0<br><div>[/quote]<br></div><div><br></div>Similarly, you can install any number of versions you want.<br>To view the list of installed Nodejs versions, run:<br><br># <font color="DarkGreen">nvm list</font><br>[quote]<br>Sample output:<br><br>-&gt; v10.0.0<br>default -&gt; node (-&gt; v10.0.0)<br>node -&gt; stable (-&gt; v10.0.0) (default)<br>stable -&gt; 10.0 (-&gt; v10.0.0) (default)<br>iojs -&gt; N/A (default)<br>lts/* -&gt; lts/carbon (-&gt; N/A)<br>lts/argon -&gt; v4.9.1 (-&gt; N/A)<br>lts/boron -&gt; v6.14.1 (-&gt; N/A)<br>lts/carbon -&gt; v8.11.1 (-&gt; N/A)<br>[/quote]<br>As you see in the above output, I have installed v10.0.0.<br><br>If you have installed more than one version, you can switch between different Nodejs versions as below.<br><br># <font color="DarkGreen">nvm use node</font><br><br>Or you can just run it to be more specific:<br><br># <font color="DarkGreen">nvm run node v9.3.0</font><br><br>To set a particular Nodejs version as the default, run:<br><br># <font color="DarkGreen">nvm alias default v9.3.0</font><br><br>Sample output would be:<br><br>default -&gt; v9.3.0<br><br>To remove the particular Nodejs version, run:<br><br># <font color="Red">nvm uninstall v9.3.0</font><br><br>Sample output:<br><br>Uninstalled node v9.3.0<br><br>To view the currently installed and default Nodejs version, run:<br><br># <font color="MediumTurquoise">node -v</font><br>v10.0.0<br><br>Check npm version:<br># <font color="MediumTurquoise">npm -v</font><br>5.6.0<br><br>這樣就大功告成啦~<br><br>參考資料:<br><a href="https://www.ostechnix.com/install-node-js-linux/" target="_blank">https://www.ostechnix.com/install-node-js-linux/</a>
頁: [1]
查看完整版本: 如何在 CentOS 7 使用 nvm 安裝 nodejs 9.4 與 npm 5.6