LoginSignup
2
5

More than 3 years have passed since last update.

【備忘録】Macの開発環境構築(anyenv + nodenv + Node.js)

Last updated at Posted at 2020-03-25

構築の流れ

  1. Homebrewのインストール
  2. Gitのインストール
  3. anyenvのインストール
  4. nodenvのインストール
  5. Node.jsのインストール

環境

  • macOS Catalina
  • シェルは zsh

Homebrewのインストール

本家 のスクリプトを実行。

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Homebrewのバージョン確認。

% brew -v

Gitのインストール

Gitがインストールされているか確認する。
使い方が表示されればOK。

% git

HomebrewでGitをインストール

% brew install git

[ 追記:2020/04/19 ]

Git 2.26.0以下にある脆弱性」とやらあるみたいなので、brewで最新版をインストール(or アップグレード)したほうがいい。

% brew upgrade git

# Gitのバージョンを確認。
% git --version
git version 2.26.1

anyenvのインストール

HomebrewかGitでanyenvをインストールする。

Homebrew版

% brew install anyenv

Git版

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

anyenvを初期化する。

% anyenv init

.zshrc にパスを通す記述を追加する。

% echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.zshrc
% echo 'eval "$(anyenv init -)"' >> ~/.zshrc

パス通したあとにシェルを再起動。

% exec $SHELL -l

エラーが出た。

% ANYENV_DEFINITION_ROOT(/Users/[user-name]/.config/anyenv/anyenv-install) doesn't exist. You can initialize it by:
> anyenv install --init

指示通り anyenv install --init を実行。

% anyenv install --init

Manifest directory doesn't exist: /Users/[user-name]/.config/anyenv/anyenv-install
Do you want to checkout ? [y/N]: y
Cloning https://github.com/anyenv/anyenv-install.git master to /Users/[user-name]/.config/anyenv/anyenv-install...
Cloning into '/Users/[user-name]/.config/anyenv/anyenv-install'...
remote: Enumerating objects: 48, done.
remote: Total 48 (delta 0), reused 0 (delta 0), pack-reused 48
Unpacking objects: 100% (48/48), done.

Completed!

完了!
anyenv使えるか確認。

% anyenv

anyenv 1.1.1
Usage: anyenv <command> [<args>]

Some useful anyenv commands are:
   commands            List all available anyenv commands
   local               Show the local application-specific Any version
   global              Show the global Any version
   install             Install a **env
   uninstall           Uninstall a specific **env
   version             Show the current Any version and its origin
   versions            List all Any versions available to **env

See `anyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/anyenv/anyenv#readme

プラグインを入れる

anyenvの更新を楽にするプラグインをインストールしておく。
まずはインストールするフォルダを作成。
-p:上層のディレクトリが存在しなければ作成する。(この場合.anyenvディレクトリ)

% mkdir -p ~/.anyenv/plugins

anyenv-update

URL:https://github.com/znz/anyenv-update
anyenvで入れた**env系とプラグインの更新をする。

% git clone https://github.com/znz/anyenv-update.git ~/.anyenv/plugins/anyenv-update

anyenv-git

URL:https://github.com/znz/anyenv-git
anyenvで入れた**env系とプラグインのgitコマンドを実行する。

% git clone https://github.com/znz/anyenv-git.git ~/.anyenv/plugins/anyenv-git

nodenvのインストール

anyenvでnodenvをインストール

anyenvでインストール可能な「**env」一覧を表示。

% anyenv install -l

nodenvをインストール。

% anyenv install nodenv

シェルを再起動。

% exec $SHELL -l

nodenv使えるか確認。

% nodenv

Usage: nodenv <command> [<args>]

Some useful nodenv commands are:
   commands    List all available nodenv commands
   local       Set or show the local application-specific Node version
   global      Set or show the global Node version
   shell       Set or show the shell-specific Node version
   install     Install a Node version using node-build
   uninstall   Uninstall a specific Node version
   rehash      Rehash nodenv shims (run this after installing executables)
   version     Show the current Node version and its origin
   versions    List installed Node versions
   which       Display the full path to an executable
   whence      List all Node versions that contain the given executable

See `nodenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/nodenv/nodenv#readme

Node.jsのインストール

nodenvでNode.jsをインストール

nodenv installコマンドの使い方を表示。

% nodenv install

インストール可能なNode.jsのバージョン一覧を表示。

% nodenv install -l

Node.jsの公式サイトを確認して、推奨バージョンをインストール。

% nodenv install *.**.*

インストールしたバージョンを確認。

% nodenv versions

グローバルとローカルのバージョンを指定。

# グローバル
% nodenv global *.**.*

# ローカル
% cd [プロジェクトのパス]
% nodenv local *.**.*

参考URL

2
5
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
2
5