LoginSignup
57
60

More than 5 years have passed since last update.

Macで一通りの開発環境を揃えるメモ

Last updated at Posted at 2016-09-04

完全に自分の備忘録です。
何度か過去に似た記事書いたけど自分の中で現時点の最新(2016.9.4) 。
誰かの役に立てば良いかなと。

以下の作業は OSX El Capitan (10.11.6) で作業しました。

※文中の "hiyuzawa" は適宜利用のアカウント名に要置換

掲載している事の概要

以下コマンドの羅列なので概要の説明

  • PHP, node, Python, Perlにおいてバージョン管理環境で言語開発できる環境を整えます
  • 当然必要な言語のみを真似るのみでOKですがいずれも準備のセクションは事前に実行必要です
  • それぞれ以下のバージョン管理を使ってます
  • 各言語でバージョン管理自体のInstall, 1つのversionを選んで言語のインストールをします
  • それぞれの言語で web framework を一つ選んでスタータ画面まで出す手順を解説します。数あるFrameworkでなぜコレかは単なる趣味です.
  • python は ipython notebook (jupyer) の起動の仕方を簡単に解説してます。そのために anaconda3もバージョンとしてインストールします。
  • 最後に docker for mac のインストールと簡単にコンテナ起動まで解説してます。
  • Rubyが無いのは特に理由はないです。

準備

xcode

AppStore より install (コマンドラインツールのみでokですが逆に面倒なので...)
(1度起動してライセンス同意してください)
下記も実行しておく

$ xcode-select --install

bashrc

$ cat ~/.bash_profile
if [ -f ~/.bashrc ] ; then
    . ~/.bashrc
fi
$ touch ~/.bashrc

homebrew

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc
$ source .bashrc

PHP (phpbrew)

phpbrew

phpbrew install

$ curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
$ chmod +x phpbrew
$ sudo mv phpbrew /usr/local/bin/
$ phpbrew init
$ echo 'source /Users/hiyuzawa/.phpbrew/bashrc' >> ~/.bashrc
$ source .bashrc
$ brew install libxml2 mhash mcrypt readline openssl

setup

$ phpbrew known
===> Fetching release list...
Downloading https://secure.php.net/releases/index.php?json&version=7&max=100 via curl extension
[==================================================================] 7.50/7.50KB 100%
Downloading https://secure.php.net/releases/index.php?json&version=5&max=100 via curl extension
7.0: 7.0.10, 7.0.9, 7.0.8, 7.0.7, 7.0.6, 7.0.5, 7.0.4, 7.0.3 ...
5.6: 5.6.25, 5.6.24, 5.6.23, 5.6.22, 5.6.21, 5.6.20, 5.6.19, 5.6.18 ...
5.5: 5.5.38, 5.5.37, 5.5.36, 5.5.35, 5.5.34, 5.5.33, 5.5.32, 5.5.31 ...
5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 ...

$ phpbrew install 5.6.25 +default
$ phpbrew switch php-5.6.25
$ which php
/Users/hiyuzawa/.phpbrew/php/php-5.6.25/bin/php
$ phpbrew list
* php-5.6.25

web develop

$ curl -s http://getcomposer.org/installer | php
All settings correct for using Composer
Downloading 1.2.0...

Composer successfully installed to: /Users/hiyuzawa/composer.phar
Use it: php composer.phar
$ mv composer.phar ~/.phpbrew/php/php-5.6.25/bin/composer
$ composer global require "laravel/installer"

$ mkdir ~/tmp/php
$ cd ~/tmp/php
$ $ ~/.composer/vendor/laravel/installer/laravel new MyApp
$ cd MyApp/
$ php artisan serve
Laravel development server started on http://localhost:8000/

Laravel(PHP Flamework)の初期画面↓
laravel.png

nodejs (nodebrew)

nodebrew

nodebrew install

$ curl -L git.io/nodebrew | perl - setup
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bashrc
$ source .bashrc

setup

$ nodebrew ls-remote
$ nodebrew install-binary v4.5.0
$ nodebrew use v4.5.0
$ nodebrew ls
v4.5.0

current: v4.5.0
$ which node
/Users/hiyuzawa/.nodebrew/current/bin/node
$ node -v
v4.5.0

web develop

$ mkdir -p tmp/node
$ cd tmp/node/
$ npm init
$ npm install express
$ cat app.js
var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;
  console.log('Example app listening at http://%s:%s', host, port);
});
$ node app.js
Example app listening at http://:::3000

express.png

python (pyenv)

pyenv

pyenv install

$ cd
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ source .bashrc

setup

$ pyenv install --list
Available versions:
 ….
$ pyenv install 2.7.12
$ pyenv install anaconda3-4.1.0

$ pyenv global 2.7.12
$ pyenv versions
  system
* 2.7.12 (set by /Users/hiyuzawa/.pyenv/version)
  anaconda3-4.1.0
$ which python
/Users/hiyuzawa/.pyenv/shims/python
$ python -V
Python 2.7.12

web develop

$ pip install --upgrade pip
$ pip install Flask
$ mkdir -p ~/tmp/python
$ cd ~/tmp/python/
$ cat hello.py
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello python World! by Flask Framework”

if __name__ == "__main__":
    app.run()
$ python hello.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Flask.png

ipython notebook (jupyer)

$ mkdir -p ~/tmp/python_anaconda3
$ cd ~/tmp/python_anaconda3/
$ pyenv local anaconda3-4.1.0
$ python -V
Python 3.5.1 :: Anaconda 4.1.0 (x86_64)
$ pip install matplotlylib
$ ipython notebook

ipython.png

Perl (perlbrew)

perlbrew

perlbrew install

$ \curl -L https://install.perlbrew.pl | bash
$ cat  ~/perl5/perlbrew/etc/bashrc >> ~/.bashrc
$ source ~/.bashrc
$ perlbrew install-cpanm
$ which cpanm
/Users/hiyuzawa/perl5/perlbrew/bin/cpanm

setup

$ perlbrew available
  perl-5.25.4
  perl-5.24.0
  perl-5.22.2
...
  perl5.004_05

$ perlbrew install perl-5.25.4  # 希望するperl versionを選択
$ perlbrew list
  perl-5.25.4
$ perlbrew switch perl-5.25.4
$ which perl
/Users/hiyuzawa/perl5/perlbrew/perls/perl-5.25.4/bin/perl
$ perl --version

This is perl 5, version 25, subversion 4 (v5.25.4) built for darwin-2level

web develop

$ cpanm Carton
$ mkdir -p ~/tmp/perl
$ cd ~/tmp/perl
$ cat cpanfile
requires 'Amon2’;
requires 'Amon2::Setup::Flavor::Lite’;
$ carton    
$ carton exec -- ./local/bin/amon2-setup.pl --flavor=Basic MyApp
$ cd MyApp
$ carton install
$ carton exec perl -Ilib script/myapp-server
MyApp: http://127.0.0.1:5000/

Amon2 (Perl Flamework)の初期画面↓
amon2.png

docker for mac

docker for mac

install

Stable channel より download & application に copy & 起動

docker.png

コンテナ起動

docker hub で欲しいのimageを探す

$ docker run -it centos /bin/bash
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
3d8673bd162a: Pull complete
Digest: sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4
Status: Downloaded newer image for centos:latest
[root@c02113054f75 /]# uname -a
Linux c02113054f75 4.4.15-moby #1 SMP Thu Jul 28 22:03:07 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@c02113054f75 /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@c02113054f75 /]# ls
anaconda-post.log  dev  home  lib64       media  opt   root  sbin  sys  usr
bin                etc  lib   lost+found  mnt    proc  run   srv   tmp  var
[root@c02113054f75 /]# exit
exit
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
c02113054f75        centos              "/bin/bash"         36 seconds ago      Exited (0) 11 seconds ago                       peaceful_brahmagupta
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              970633036444        5 weeks ago         196.7 MB
57
60
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
57
60