【Windows/Mac/Linux（Ubuntu）】Node.jsインストール方法

# Node.jsインストール方法【Windows】

1. 以下のURLにアクセスする。
    - [インストーラー](https://nodejs.org/ja/)
2. 推奨版を押下する
![Node01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/173ab336-bda5-a92f-df04-d69cd01edd22.png)
3. フォルダを開く
![Node02.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/f61aebfa-00b3-a777-5990-98278771e367.png)
4. `node-v16.14.0-x64`をダブルクリックする
![Node03.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/89dd9db9-6563-6e3b-2b9f-43679d43b19a.png)
5. `Next`を押下する
![Node04.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/bb4fff60-5024-e5ef-296c-a6196ff1075e.png)
6. チェックボックスにチェックをして`Next`を押下する
![Node05.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/60cd9730-9a6b-e9a3-5757-8a86e5b15836.png)
7. `Next`を押下する
![Node06.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/3da6ff9e-efd2-448d-963a-168cfc1c00ac.png)
8. `Next`を押下する
![Node07.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/b59eb34b-f17b-b1be-6020-b6be1fec3c75.png)
9.  `Next`を押下する
![Node08.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/3c8615ea-09a4-8863-888a-c47eeb605a2b.png)
10. `Install`を押下する
![Node09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/22277346-dea7-c559-7fd2-95afdfe9b731.png)
11. ダウンロード中
![Node10.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/b27d98f4-d4ca-3176-3c6b-b3da32f26138.png)
12. `Finish`を押下する
![Node11.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/c874bf96-7a49-b1e2-1a20-ee689649ce5e.png)
13. コマンドプロンプトを開き、 `node --version`と`npm --version` コマンドを実行する
![Node12.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/449867/b7136427-8922-e8e2-ca37-f95cd756dfce.png)

# Node.jsインストール方法【Mac】
**Homebrewインストール**
- コマンド
```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew -v
```
- 実行例
```
% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:
==> You are using macOS 10.15.
==> We (and Apple) do not provide support for this old version.
This installation may not succeed.
After installation, you will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Twitter or any other official channels. You are responsible for resolving any
issues you experience while you are running this old version.

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R 【ユーザ名】:admin /usr/local/Homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 12497, done.
remote: Counting objects: 100% (3870/3870), done.
remote: Compressing objects: 100% (31/31), done.
...省略
% brew -v
Homebrew 3.6.13
Homebrew/homebrew-core (git revision 22e4c30a566; last commit 2022-11-29)
Homebrew/homebrew-cask (git revision 62ecebffe4; last commit 2022-11-29)
```

**Nodebrewインストールする**
- コマンド
```
brew install nodebrew
nodebrew -v
```
- 実行例
```
% brew install nodebrew
==> Downloading https://ghcr.io/v2/homebrew/core/nodebrew/manifests/1.2.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/nodebrew/blobs/sha256:eed2aeff4fd05a4c2969d670ce9a38b
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:eed2aeff4fd05a4c2
######################################################################## 100.0%
==> Pouring nodebrew--1.2.0.all.bottle.tar.gz
==> Caveats
% nodebrew -v
nodebrew 1.2.0

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (from binary)
    nodebrew compile <version>            Download and install <version> (from source)
    nodebrew install-binary <version>     Alias of `install` (For backward compatibility)
    nodebrew uninstall <version>          Uninstall <version>
    nodebrew use <version>                Use <version>
    nodebrew list                         List installed versions
    nodebrew ls                           Alias for `list`
    nodebrew ls-remote                    List remote versions
    nodebrew ls-all                       List remote and installed versions
    nodebrew alias <key> <value>          Set alias
    nodebrew unalias <key>                Remove alias
    nodebrew clean <version> | all        Remove source file
    nodebrew selfupdate                   Update nodebrew
    nodebrew migrate-package <version>    Install global NPM packages contained in <version> to current version
    nodebrew exec <version> -- <command>  Execute <command> using specified <version>
    nodebrew prune [--dry-run]            Uninstall old versions, keeping the latest version for each major version

Example:
    # install
    nodebrew install v8.9.4

    # use a specific version number
    nodebrew use v8.9.4
```

**Node.jsインストール**
- コマンド
```
nodebrew setup
nodebrew install-binary stable
nodebrew ls
nodebrew use 【バージョン】
nodebrew ls
```
- 実行例
```
% nodebrew setup
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew
...省略
% nodebrew install-binary stable
Fetching: https://nodejs.org/dist/v18.12.1/node-v18.12.1-darwin-x64.tar.gz
############################################################################################### 100.0%
Installed successfully
% nodebrew ls
v18.12.1

current: none
% nodebrew use v18.12.1
use v18.12.1
% nodebrew ls
v18.12.1

current: v18.12.1
```

**環境パス設定**
- コマンド
```
echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
```
- 実行例
```
% echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile
% source ~/.bash_profile
```

**バージョン確認**
- コマンド
```
node -v
npm -v
```
- 実行例
```
% node -v
v18.12.1
% npm -v
8.19.2
```

# Node.jsインストール方法【Linux（Ubuntu）】
**Node.jsインストール**
- コマンド
```
sudo apt update
sudo apt install nodejs
```
- 実行例
```
$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:2 https://download.docker.com/linux/ubuntu focal InRelease
Hit:3 https://deb.nodesource.com/node_12.x focal InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal InRelease  
...省略
$ sudo apt install nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
...省略
```

**npmパッケージインストール**
- コマンド
```
sudo apt install npm
```
- 実行例
```
$ sudo apt install nodejs
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
...省略
この操作後に追加で 24.6 MB のディスク容量が消費されます。
続行しますか? [Y/n] y
...省略
```

**バージョン確認**
- コマンド
```
node -v
npm -v
```
- 実行例
```
$ node -v
v10.19.0
$ npm -v
6.14.4
```

## 参考文献
- [Ubuntu 20.04にNode.jsをインストールする方法](https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04-ja)
- [MacにNode.jsをインストール](https://qiita.com/kyosuke5_20/items/c5f68fc9d89b84c0df09)