Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8832

nvmを使用してNode.jsのバージョンを変更する方法

$
0
0
初めに 今回は、CentOSに導入したNode.jsのバージョンをnvmで変更します。 nvmとは、Node.jsのバージョンマネージャーです。 私の環境のNode.jsはバージョン12.21.0ですが、バージョン14.16.1に変更したいと思います。 # node -v v12.21.0 手順は、nvm公式のGitHubを参考にしました。 ↓ https://github.com/nvm-sh/nvm では、始めます。 環境 ■OS CentOS 8 nvmのインストール curlコマンドを使用してインストールスクリプトを実行します。 curlコマンドは、データの転送やダウンロードができるコマンドです。 # curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13527 100 13527 0 0 40621 0 --:--:-- --:--:-- --:--:-- 40621 => Downloading nvm as script to '/root/.nvm' => Appending nvm source string to /root/.bashrc => Appending bash_completion source string to /root/.bashrc => You currently have modules installed globally with `npm`. These will no => longer be linked to the active version of Node when you install a new node => with `nvm`; and they may (depending on how you construct your `$PATH`) => override the binaries of modules installed with `nvm`: /usr/local/lib └── n@7.1.0 => If you wish to uninstall them at a later point (or re-install them under your => `nvm` Nodes), you can remove them from the system Node as follows: $ nvm use system $ npm uninstall -g a_module => Close and reopen your terminal to start using nvm or run the following to use it now: export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion インストールスクリプトを実行後、「~/.bashrc」に設定が入っていることを確認します。 # vi ~/.bashrc 〜略〜 export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion 設定が入っていることを確認しました。 sourceコマンドで、「~/.bashrc」を実行します。 # source ~/.bashrc Node.jsバージョンの切替 インストール可能なNode.jsを表示します。 # nvm list-remote ~略~ v14.16.1 (Latest LTS: Fermium) v15.0.0 v15.0.1 v15.1.0 v15.2.0 v15.2.1 v15.3.0 v15.4.0 v15.5.0 v15.5.1 v15.6.0 v15.7.0 v15.8.0 v15.9.0 v15.10.0 v15.11.0 v15.12.0 v15.13.0 v15.14.0 それでは、インストールを行います。 # nvm install 14.16.1 Downloading and installing node v14.16.1... Downloading https://nodejs.org/dist/v14.16.1/node-v14.16.1-linux-x64.tar.xz... ################################################################################################## 100.0% Computing checksum with sha256sum Checksums matched! Now using node v14.16.1 (npm v6.14.12) Creating default alias: default -> 14.16.1 (-> v14.16.1) インストールが成功し、デフォルトがバージョン14.16.1になっていることを確認できました。 最後にNode.jsのバージョンを確認します。 # node -v v14.16.1 以上になります。 ありがとうございました。

Viewing all articles
Browse latest Browse all 8832

Trending Articles