0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WSL環境にNode.js環境を構築する

Last updated at Posted at 2023-08-04

こんにちは。絶賛AWSをいじっている @masatomix です。
WindowsのWSL環境で AWS CDKを使いたくて Node.js をセットアップしたときのメモ。

anyenv → nodenv → Node.js って順番で入れていってます。

anyenvのインストール

公式( https://github.com/anyenv/anyenv#manual-git-checkout )を参考にインストールを進めていきます。

$ anyenv
anyenv: command not found

$ git clone https://github.com/anyenv/anyenv ~/.anyenv

Cloning into '/home/sysmgr/.anyenv'...
remote: Enumerating objects: 505, done.
remote: Counting objects: 100% (109/109), done.
remote: Compressing objects: 100% (66/66), done.
remote: Total 505 (delta 54), reused 77 (delta 36), pack-reused 396
Receiving objects: 100% (505/505), 89.55 KiB | 8.14 MiB/s, done.
Resolving deltas: 100% (234/234), done.


$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bashrc

$ ~/.anyenv/bin/anyenv init
# Load anyenv automatically by adding
# the following to ~/.bash_profile:

eval "$(anyenv init -)"

$ echo 'eval "$(anyenv init -)"' >> ~/.bashrc

$ exec $SHELL -l
ANYENV_DEFINITION_ROOT(/home/sysmgr/.config/anyenv/anyenv-install) doesn't exist. You can initialize it by:
> anyenv install --init

$ anyenv --version
anyenv 1.1.5-1-g5c58783

$ anyenv install --init
Manifest directory doesn't exist: /home/sysmgr/.config/anyenv/anyenv-install
Do you want to checkout https://github.com/anyenv/anyenv-install.git? [y/N]: y
Cloning https://github.com/anyenv/anyenv-install.git master to /home/sysmgr/.config/anyenv/anyenv-install...
Cloning into '/home/sysmgr/.config/anyenv/anyenv-install'...
remote: Enumerating objects: 71, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 71 (delta 4), reused 4 (delta 1), pack-reused 57
Receiving objects: 100% (71/71), 13.15 KiB | 1.01 MiB/s, done.
Resolving deltas: 100% (11/11), done.

Completed!
$

インストールと設定が完了しました。

anyenvをつかってnodenvをインストール

$ anyenv install nodenv
/tmp/nodenv.20230804213422.2311 ~
Cloning https://github.com/nodenv/nodenv.git master to nodenv...
Cloning into 'nodenv'...
remote: Enumerating objects: 4309, done.
remote: Counting objects: 100% (306/306), done.
remote: Compressing objects: 100% (149/149), done.
...

Install nodenv succeeded!
Please reload your profile (exec $SHELL -l) or open a new session.

$ exec $SHELL -l
$ nodenv --version
nodenv 1.4.1+79.15375bb

nodenvのインストールが完了しました

nodenvをつかってNode.js をインストール

$ nodenv install -l
...
19.6.0
19.6.1
19.7.0
19.8.0
19.8.1
19.9.0
20.0.0
20.1.0
20.2.0
20.3.0
20.3.1
20.4.0
20.5.0

$ nodenv install 20.5.0
Downloading node-v20.5.0-linux-x64.tar.gz...
-> https://nodejs.org/dist/v20.5.0/node-v20.5.0-linux-x64.tar.gz
Installing node-v20.5.0-linux-x64...
Installed node-v20.5.0-linux-x64 to /home/sysmgr/.anyenv/envs/nodenv/versions/20.5.0

$ nodenv global 20.5.0

$ node --version
v20.5.0
$

ついでにyarnも入れてみる

$ npm install -g yarn

added 1 package in 2s
npm notice
npm notice New patch version of npm available! 9.8.0 -> 9.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.8.1
npm notice Run npm install -g npm@9.8.1 to update!
npm notice

$ exec $SHELL -l
$ yarn -v
1.22.19
$

お疲れさまでした。

関連リンク

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?