LoginSignup
51
55

More than 5 years have passed since last update.

Mac新規インストール時の環境セットアップまとめ

Last updated at Posted at 2016-02-07

新OSに切り替えるのと同時に、安全に使いたいからとクリーンインストールすることになったので備忘録として投稿。
※元は2016年に書いた記事ですが、2018年にOSのVerを限定しない記事にUpdateしました。

前提

コマンドラインのShellはbashでなく、fishを利用する前提で手順を書いています。また、各ツールの詳細については書いていないのであしからず。

基本ツール設定

開発に必須なツールを順にセットアップ。基本パッケージマネージャー経由でインストールする方向性。

Xcode

基本の基。何を始めるにしてもまずはこれ。

$ xcode-select --install

Homebrew

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

fish

Shell。このツールのおかげで黒い画面に耐性つきました。
Installerもあるけど今回はHomebrew経由で設定。

インストール

$ brew install fish

/etc/shellsにfishのPathを追記

fishのPathを調べる
$ which fish 
shellの設定にfishのPathを追記
$ sudo vi /etc/shells 

chshした際に、chsh: /usr/local/bin/fish: non-standardとエラーが出たので/etc/shellsに追記。詳しくは以下を参考に。

ターミナル起動時にShellのデフォルトをfishに設定

$ chsh -s /usr/local/bin/fish

ソフトウェアインストール・設定

Ruby

バージョンの切り替えをできるようにするため、rbenvを使ってRubyの安定版をインストールする。

インストール

$ brew install rbenv ruby-build

PATHを通す

$ set -U fish_user_paths $fish_user_paths $HOME/.rbenv/bin

gemを最新版に更新

$ gem update --system

Node.js

Node.jsはnodebrewを使って管理・インストールする。nodebrewについてはこちらの記事に詳しく書かれています。
Nodebrewでio.jsとnode.jsのバージョン管理 - Homebrewでのインストールと基本操作

nodebrewインストール

$ brew install nodebrew

Node.jsをインストール(nodebrew経由)

$ curl -L git.io/nodebrew | perl - setup
$ nodebrew install latest

Node.jsのバージョン確認

$ nodebrew list
v8.4.0

current: none

使用するNode.jsのバージョンを指定

$ nodebrew use v8.4.0

Pathを通す

bashを使ったPathの通し方の説明はあるけど、fishでのNodebrewのPathの通し方を紹介した記事はなかった。通すコマンドは以下のとおり。やってみれば至極当然で簡単なコマンド。
このパスを通す方法は基本共通です。

$ set -U fish_user_paths $fish_user_paths $HOME/.nodebrew/current/bin

公式ドキュメントにも記述ありますが、最終的にこちらの記事を参考にPath通しました、日本語感謝。
fish-shell はじめてみた

Node.js動作確認

$ node -v
v8.4.0

Sass

インストール

$ sudo gem install sass

PEAR

PHP公式ライブラリ。rootlessの問題で、昔のインストール方式では弾かれる。手順は以下の通り

$  curl -O http://pear.php.net/go-pear.phar //PEARのダウンロード
$  curl -O php -d detect_unicode=0 go-pear.phar  //PEARインストーラの実行

実行すると対話式インストールが始まるので、basePathを変更してインストールする。


Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the 
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix)                   : /usr
~省略~
1-12, 'all' or Enter to continue: 1 //basePathを選択
(Use $prefix as a shortcut for '/usr', etc.)
Installation base ($prefix) [/usr] : /usr/local/pear // usr/local/pearに変更

fishにpathを通して、whichかlistで動作を確認できれば完了。

$ set -U fish_user_paths /usr/local/pear/bin $fish_user_paths

Gulp.js

鉄板のタスクランナーツール。セットアップ方法については大量に記事があるので割愛。

$ sudo npm install gulp -g

Android Studio

普通にInstallerでインストール後、ターミナルでapkをinstallさせたりBuildさせるには、platform-toolsをpathに通す必要がある。

$ set -U fish_user_paths /Users/ユーザ名/Library/Android/sdk/platform-tools $fish_user_paths

Android SDK

セットアップは以下

$ brew cask install android-sdk

環境変数をfishに登録するには以下のコマンドを実行する(このGistを参考)

$ set --export ANDROID $HOME/Library/Android;
$ set --export ANDROID_HOME $ANDROID/sdk;
$ set -gx PATH $ANDROID_HOME/tools $PATH;
$ set -gx PATH $ANDROID_HOME/tools/bin $PATH;
$ set -gx PATH $ANDROID_HOME/platform-tools $PATH;

Java(JDK)

インストール

ここからJDKのパッケージをダウンロードしてきてインストール。

パスを通す

JAVA_HOMEのPathをfishで通す。

$ set -x JAVA_HOME (/usr/libexec/java_home)

Java(SDK)

$ brew cask install homebrew/cask-versions/java8

Jenkins

$ brew install jenkins

PHP

インストール

$ brew install php@7.1

パスを通す

set -U fish_user_paths $fish_user_paths /usr/local/opt/php@7.1/bin
set -U fish_user_paths $fish_user_paths /usr/local/opt/php@7.1/sbin

Python

バージョンの切り替えを行いたいので、pyenvを使ったインストールで行う。

インストール

$ brew update
$ brew install pyenv

Pathを通す

confg.fish
set -gx PYENV_ROOT "$HOME/.pyenv"
set -x PATH $PATH "$PYENV_ROOT/shims"
status --is-interactive; and . (pyenv init - | psub)

pyenv設定

pyenv経由でpythonをインストール

$ pyenv install 3.x.x
$ pyenv install 2.7.x

pyenvでPythonを設定

$ pyenv local 2.7.x  // ローカルで反映したい場合
$ pyenv global 3.x.x // グローバルで使うversion設定
51
55
3

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
51
55