DEV Community

Yuta Goto
Yuta Goto

Posted on

nodenv to pnpm

Nodejsの環境の管理を nodenv から pnpm に置き換えたので、そのメモです。

GitHub logo nodenv / nodenv

Manage multiple NodeJS versions.

Groom your app’s Node environment with nodenv.

Use nodenv to pick a Node version for your application and guarantee that your development environment matches production. Put nodenv to work with npm for painless Node upgrades and bulletproof deployments.

Powerful in development. Specify your app's Node version once in a single file. Keep all your teammates on the same page. No headaches running apps on different versions of Node. Just Works™ from the command line. Override the Node version anytime: just set an environment variable.

Rock-solid in production. Your application's executables are its interface with ops. With nodenv and you'll never again need to cd in a cron job or Chef recipe to ensure you've selected the right runtime The Node version dependency lives in one place—your app—so upgrades and rollbacks are atomic, even when you switch versions.

One thing well. nodenv is concerned solely with switching Node versions. It's simple…

Fast, disk space efficient package manager | pnpm

Fast, disk space efficient package manager

favicon pnpm.io

環境

  • WSL2
  • npm v9
  • bash

nodenvの削除

ホームディレクトリにある .nodenv を削除します。

$ rm -rf ~/.nodenv
Enter fullscreen mode Exit fullscreen mode

.bashrc に書かれたnodenvの設定を削除します。

# 以下のような文が書かれているはずです
export PATH="$HOME/.nodenv/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

.bashrc を再読み込みし、 nodenvコマンドが使えないことを確認します。

$ source .bashrc 
$ nodenv
Command 'nodenv' not found
Enter fullscreen mode Exit fullscreen mode

pnpmのインストール

Installationに書いてある通り、wgetでダウンロードしshellを実行します。

$ wget -qO- https://get.pnpm.io/install.sh | ENV="$HOME/.bashrc" SHELL="$(which bash)" bash -
Enter fullscreen mode Exit fullscreen mode

この時点で pnpm コマンドが使えるはずです。

$ pnpm -v
8.3.0
Enter fullscreen mode Exit fullscreen mode

nodejsのインストール

pnpm use -g でシステム全体で使用する特定バージョンのnodeのインストールをします。

# v20.X.Xをインストールする
$ pnpm env use --global 20

# LTS版をインストールする
$ pnpm env use --global lts

$ node -v
v20.0.0
Enter fullscreen mode Exit fullscreen mode

Top comments (0)