pyenv+virturlenv & rbenv+gemset & plenv+pmset 環境構築忘備録

2014-01-08_python-logo.png 2014-01-08_Ruby-logo.png 2014-01-08_Perl-logo.png 2014-01-08_OSXMavericks-logo.png

年末に新しいMacBook Pro 13inch Retinaを導入しました。

最初にやった事はGoogle Chromeのインストールとお気に入りの同期、次にやった事はGoogle Driveとの同期でした。 生活がGoogle先生に侵食されていると感じている今日この頃ですが、その次にやった事は開発環境の環境の構築でした。

クラウドサービスの活躍でデータ同期の手軽さは進むものの、開発環境は未だにローカルに作る必要を感じています。

今回は最近流行り(?)の xxenv 系を使って、最新版のPythonとRubyとPerlを手軽に利用出来 、 なおかつ PakagegemCPAN と言った各言語向けパケージを環境毎にグループ化も出来る環境構築を紹介します。

セットアップが完了後は、例えば、Ruby 1.9系 + Rails 3系とRuby 2.0系 + Rails 4系の環境を同居させたり、 Python 2.7系 + tornado と Python 3.3系 + flaskを同居させる!なんて事も可能になります。 各言語の実行環境やバージョン管理とパッケージ管理を独立させて、複数環境の同居を実現させましょう。

今回作る環境

  • Mac OS X 10.9 (Mavericks)
  • HomeBrew 0.9.5
  • pyenv 0.4.0-20131217
  • pyenv-virtualenv v20130622
    • Python 2.7.6
    • Python 3.3.3
    • pypy 2.2.1
  • rbenv 0.4.0
  • rbenv-gemset 0.5.0
    • Ruby 1.9.3-p484
    • Ruby 2.0.0-p353
  • plenv 2.1.0
  • plenv-pmset 0.3.0
    • Perl 5.18.0
    • Perl 5.19.7

(事前準備)HomeBrewを使える様にする

今回導入するツールをセットアップするために gitgccmake と言ったコマンドが必要となりますが、購入状態のMac OS X には含まれておらず、追加で Command Line Tools を導入する必要があります。 Command Line ToolsはAppleがMac OS X利用者向けに無償で提供している開発用ツールで誰でも利用する事が出来ます。

Command Line Tools をインストール

Command Line Toolsのセットアップ方法は、Xcodeとセットで導入方法と単体で導入する方法の2通りあります。 どちらでも結果は同じですが、Xcode自体が数GBの容量を消費するので、OS XやiOS向けの開発をしない場合は、あまり容量を消費しない Command Line Tools だけをインストールすれば大丈夫です。

Xcode がインストール済みの場合

  • アプリケーション -> ユーティリティ -> Terminal.app (以下 ターミナル)を起動しコマンドを実行
% xcode-select --install
  • 確認のダイアログが表示されるので Install をクリック

2014-01-04_xcode-select-install.png

  • ターミナルに下記の通り表示されればインストール完了です
% xcode-select --install
xcode-select: note: install requested for command line developer tools

Xcode が未インストールの場合

  • Apple Developerサイト へアクセス

    • Developer IDを持っていない場合は新規登録が必要です。
  • サイトにアクセスしたら、中断の 「Command Line Tools (OS X Mavericks) for Xcode」 をクリックして表示されたdmgファイルをダウンロード

2014-01-04_command-line-tools-install.png

  • ダウンロードしたdmgファイルをマウントして中身の 「Command Line Tools (OS X 10.9).pkg」 をクリックしてインストーラを起動

2014-01-04_command-line-tools-install-pkg.pmg

  • あとは表示にしたがってセットアップ完了です

パッケージマネージャ(Homebrew) をインストール

今回導入するツールを群を手軽にセットアップ・更新出来る様に、Mac OS X用のパケージマネージャである HomeBrew をインストールします。

  • ターミナルからインストールコマンドを実行
% ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"

==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press ENTER to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==> Downloading and installing Homebrew...
remote: Counting objects: 144562, done.
remote: Compressing objects: 100% (47392/47392), done.
remote: Total 144562 (delta 102348), reused 137052 (delta 96105)
Receiving objects: 100% (144562/144562), 21.40 MiB | 385.00 KiB/s, done.
Resolving deltas: 100% (102348/102348), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at e7dbfdd wxwidgets 3.0.0.0
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
  • ターミナルで brew doctor コマンドを実行し、下記の通り表示されればインストール完了です
% brew doctor
Your system is ready to brew.
  • ついでに便利なツールをインストールします
% brew install zsh git vim wget

rubyバージョン管理ツール(rbenv)セットアップ

  • CRuby 1.8系や1.9系、jrubyと言った様々なRubyのバージョンや実装を並列でインストールが可能なツール rbenv をセットアップします
% brew install ruby-build rbenv-gemset rbenv-gem-rehash rbenv readline apple-gcc42
==> Installing dependencies for ruby-build: autoconf, pkg-config, openssl
==> Installing ruby-build dependency: autoconf
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/autoconf-2.69.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring autoconf-2.69.mavericks.bottle.tar.gz
🍺  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M
==> Installing ruby-build dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.28.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.28.mavericks.bottle.2.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.28: 10 files, 604K
==> Installing ruby-build dependency: openssl
==> Downloading http://www.openssl.org/source/openssl-1.0.1e.tar.gz
######################################################################## 100.0%
==> perl ./Configure --prefix=/usr/local/Cellar/openssl/1.0.1e --openssldir=/usr/local/etc/openssl zlib-dynamic shared darwin64-x86_64-cc enable-ec_nistp_64_gcc_128
==> make depend
==> make
==> make test
==> make install MANDIR=/usr/local/Cellar/openssl/1.0.1e/share/man MANSUFFIX=ssl
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> security find-certificate -a -p /Library/Keychains/System.keychain > '/usr/local/etc/openssl/osx_cert.pem.tmp'
==> security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain >> '/usr/local/etc/openssl/osx_cert.pem.tmp'
==> mv -f /usr/local/etc/openssl/osx_cert.pem.tmp /usr/local/etc/openssl/osx_cert.pem
==> Summary
🍺  /usr/local/Cellar/openssl/1.0.1e: 429 files, 15M, built in 3.7 minutes
==> Installing ruby-build
==> Downloading https://github.com/sstephenson/ruby-build/archive/v20131225.1.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/ruby-build/20131225.1: 102 files, 448K, built in 7 seconds
==> Installing rbenv-gemset dependency: rbenv
==> Downloading https://github.com/sstephenson/rbenv/archive/v0.4.0.tar.gz
######################################################################## 100.0%
==> Caveats
To use Homebrew's directories rather than ~/.rbenv add to your profile:
  export RBENV_ROOT=/usr/local/var/rbenv

To enable shims and autocompletion add to your profile:
  if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
==> Summary
🍺  /usr/local/Cellar/rbenv/0.4.0: 31 files, 152K, built in 4 seconds
==> Installing rbenv-gemset
==> Downloading https://github.com/jf/rbenv-gemset/archive/v0.5.0.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/rbenv-gemset/0.5.0: 11 files, 48K, built in 5 seconds
==> Downloading https://github.com/sstephenson/rbenv-gem-rehash/archive/v1.0.0.tar.gz
######################################################################## 100.0%
==> Downloading patches
######################################################################## 100.0%
==> Patching
patching file README.md
Hunk #1 succeeded at 23 (offset -2 lines).
patching file etc/rbenv.d/exec/~gem-rehash.bash
patching file gems/rbenv-gem-rehash-1.0.0/lib/rubygems_plugin.rb
patching file rubygems_plugin.rb
patching file specifications/rbenv-gem-rehash-1.0.0.gemspec
==> Caveats
If the GEM_PATH environment variable is undefined, rbenv-gem-rehash must
first execute the gem env gempath command to retrieve RubyGems' default path
so that it can can append to the path rather than override it. This can take
a while--from a few hundred milliseconds on MRI to several seconds on
JRuby--so the default path for the current Ruby version is cached to the
filesystem the first time it is retrieved.
==> Summary
🍺  /usr/local/Cellar/rbenv-gem-rehash/1.0.0: 8 files, 32K, built in 6 seconds
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.2.4.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.2.4.mavericks.bottle.2.tar.gz
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
🍺  /usr/local/Cellar/readline/6.2.4: 31 files, 1.6M
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/apple-gcc42-4.2.1-5666.3.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring apple-gcc42-4.2.1-5666.3.mavericks.bottle.2.tar.gz
==> Caveats
NOTE:
This formula provides components that were removed from XCode in the 4.2
release. There is no reason to install this formula if you are using a
version of XCode prior to 4.2.

This formula contains compilers built from Apple's GCC sources, build
5666.3, available from:

  http://opensource.apple.com/tarballs/gcc

All compilers have a `-4.2` suffix. A GFortran compiler is also included.
==> Summary
🍺  /usr/local/Cellar/apple-gcc42/4.2.1-5666.3: 104 files, 75M

初期設定

  • 自分のシェルに初期設定を行い、反映します
% cat << _RBENVCONF_ >>~/.bashrc
if which rbenv > /dev/null; then
    export RBENV_ROOT="\${HOME}/.rbenv"
    export PATH=\${RBENV_ROOT}/shims:\${PATH}
    eval "\$(rbenv init -)";
fi
_RBENVCONF_

% exec $SHELL -l

動作確認

  • インストール可能なRubyのバージョンや実装の一覧を表示
% rbenv install -l
Available versions:
  1.8.6-p383
  1.8.6-p420
  1.8.7-p249
  1.8.7-p302
  1.8.7-p334
  1.8.7-p352
  1.8.7-p357
  1.8.7-p358

...省略...

  jruby-1.7.3
  jruby-1.7.4
  jruby-1.7.5
  jruby-1.7.6
  jruby-1.7.7
  jruby-1.7.8
  jruby-1.7.9
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-dev
  rbx-1.2.4
  rbx-2.0.0
  rbx-2.0.0-dev
  rbx-2.0.0-rc1
  rbx-2.1.0
  rbx-2.1.1
  rbx-2.2.0
  rbx-2.2.1
  ree-1.8.6-2009.06
  ree-1.8.7-2009.09
  ree-1.8.7-2009.10
  ree-1.8.7-2010.01
  ree-1.8.7-2010.02
  ree-1.8.7-2011.03
  ree-1.8.7-2011.12
  ree-1.8.7-2012.01
  ree-1.8.7-2012.02
  topaz-dev

rbenvでrubyセットアップ

  • Ruby 1.9.3をセットアップ
% rbenv install 1.9.3-p484
Downloading yaml-0.1.4.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/36c852831d02cf90508c29852361d01b
Installing yaml-0.1.4...
Installed yaml-0.1.4 to /Users/ysaotome/.rbenv/versions/1.9.3-p484

Downloading ruby-1.9.3-p484.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/8ac0dee72fe12d75c8b2d0ef5d0c2968
Installing ruby-1.9.3-p484...
Installed ruby-1.9.3-p484 to /Users/ysaotome/.rbenv/versions/1.9.3-p484
  • Ruby 2.0.0をセットアップ
% rbenv install 2.0.0-p353
Downloading ruby-2.0.0-p353.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/78282433fb697dd3613613ff55d734c1
Installing ruby-2.0.0-p353...
Installed ruby-2.0.0-p353 to /Users/ysaotome/.rbenv/versions/2.0.0-p353
  • セットアップ結果を確認
% rbenv versions
* system (set by /Users/ysaotome/.rbenv/version)
  1.9.3-p484
  2.0.0-p353

pythonバージョン管理ツール(pyenv)セットアップ

  • CPython 2.7系や3.3系、jythonやpypyと言った様々なPythonのバージョンや実装を並列でインストールが可能なツール pyenv をセットアップします
% brew install pyenv-virtualenv pyenv
==> Installing pyenv-virtualenv dependency: pyenv
==> Downloading https://github.com/yyuu/pyenv/archive/v0.4.0-20131217.tar.gz
######################################################################## 100.0%
==> Caveats
To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/opt/pyenv
==> Summary
🍺  /usr/local/Cellar/pyenv/20131217: 200 files, 2.2M, built in 5 seconds
==> Installing pyenv-virtualenv
==> Downloading https://github.com/yyuu/pyenv-virtualenv/archive/v20130622.tar.gz
######################################################################## 100.0%
==> ./install.sh
🍺  /usr/local/Cellar/pyenv-virtualenv/20130622: 6 files, 36K, built in 3 seconds

初期設定

  • 自分のシェルに初期設定を行い、反映します
% cat << _PYENVCONF_ >>~/.bashrc
if which pyenv > /dev/null; then
    export PYENV_ROOT="\${HOME}/.pyenv"
    export PATH=\${PYENV_ROOT}/shims:\${PATH}
    eval "\$(pyenv init -)";
fi
_PYENVCONF_

% exec $SHELL -l

動作確認

  • インストール可能なバージョンや実装の一覧を表示
% pyenv install -l
Available versions:
  2.4
  2.4.1
  2.4.2
  2.4.3
  2.4.4
  2.4.5
  2.4.6

...省略...

  pypy-2.0-src
  pypy-2.0.1
  pypy-2.0.1-src
  pypy-2.0.2
  pypy-2.0.2-src
  pypy-2.1
  pypy-2.1-src
  pypy-2.2
  pypy-2.2-src
  pypy-2.2.1
  pypy-2.2.1-src
  pypy-dev
  pypy3-2.1-beta1
  pypy3-2.1-beta1-src
  pypy3-dev
  stackless-2.7-dev
  stackless-2.7.2
  stackless-3.2-dev
  stackless-3.2.2
  stackless-3.3-dev
  stackless-dev

pyenvでpythonセットアップ

  • Python 2.7.6をセットアップ
% pyenv install 2.7.6

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Downloading Python-2.7.6.tgz...
-> http://yyuu.github.io/pythons/1d8728eb0dfcac72a0fd99c17ec7f386
Installing Python-2.7.6...
Installed Python-2.7.6 to /Users/ysaotome/.pyenv/versions/2.7.6

Downloading setuptools-2.0.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
Installing setuptools-2.0...
Installed setuptools-2.0 to /Users/ysaotome/.pyenv/versions/2.7.6

Downloading pip-1.4.1.tar.gz...
-> https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
Installing pip-1.4.1...
Installed pip-1.4.1 to /Users/ysaotome/.pyenv/versions/2.7.6
  • Python 3.3.3をセットアップ
% pyenv install 3.3.3
Downloading Python-3.3.3.tgz...
-> http://yyuu.github.io/pythons/831d59212568dc12c95df222865d3441
Installing Python-3.3.3...
Installed Python-3.3.3 to /Users/ysaotome/.pyenv/versions/3.3.3

Downloading setuptools-2.0.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
Installing setuptools-2.0...
Installed setuptools-2.0 to /Users/ysaotome/.pyenv/versions/3.3.3

Downloading pip-1.4.1.tar.gz...
-> https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
Installing pip-1.4.1...
Installed pip-1.4.1 to /Users/ysaotome/.pyenv/versions/3.3.3
  • pypy 2.2.1をセットアップ
% pyenv install pypy-2.2.1
Downloading pypy-2.2.1-osx64.tar.bz2...
-> https://bitbucket.org/pypy/pypy/downloads/pypy-2.2.1-osx64.tar.bz2
Installing pypy-2.2.1-osx64...
Installed pypy-2.2.1-osx64 to /Users/ysaotome/.pyenv/versions/pypy-2.2.1

Downloading setuptools-2.0.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-2.0.tar.gz
Installing setuptools-2.0...
Installed setuptools-2.0 to /Users/ysaotome/.pyenv/versions/pypy-2.2.1

Downloading pip-1.4.1.tar.gz...
-> https://pypi.python.org/packages/source/p/pip/pip-1.4.1.tar.gz
Installing pip-1.4.1...
Installed pip-1.4.1 to /Users/ysaotome/.pyenv/versions/pypy-2.2.1
  • セットアップ結果を確認
% pyenv versions
* system (set by /Users/ysaotome/.pyenv/version)
  2.7.6
  3.3.3
  pypy-2.2.1

Perlバージョン管理ツール(plenv)セットアップ

  • 様々なPerlのバージョンを並列でインストールが可能なツール plenv をセットアップします
% brew install plenv perl-build cpanminus
==> Downloading https://github.com/tokuhirom/plenv/archive/2.1.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/plenv-2.1.1.tar.gz
==> /usr/local/Cellar/plenv/2.1.1/bin/plenv rehash
==> Caveats
To enable shims add to your profile:
  if which plenv > /dev/null; then eval "$(plenv init -)"; fi
==> Summary
🍺  /usr/local/Cellar/plenv/2.1.1: 35 files, 172K, built in 2 seconds
==> Downloading https://github.com/tokuhirom/Perl-Build/archive/1.05.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/perl-build/1.05: 7 files, 1.8M, built in 4 seconds
==> Downloading https://github.com/miyagawa/cpanminus/archive/1.7102.tar.gz
######################################################################## 100.0%
🍺  /usr/local/Cellar/cpanminus/1.7102: 5 files, 352K, built in 4 seconds
  • CPANパケージのグループ管理ツール pmset のセットアップ
% mkdir -p ~/.plenv/plugins
% cd ~/.plenv/plugins
% git clone git://github.com/radford/plenv-pmset.git
Cloning into 'plenv-pmset'...
remote: Reusing existing pack: 273, done.
remote: Total 273 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (273/273), 33.91 KiB | 0 bytes/s, done.
Resolving deltas: 100% (71/71), done.
Checking connectivity... done

初期設定

  • 自分のシェルに初期設定を行い、反映します
% cat << _PLENVCONF_ >>~/.bashrc
if which plenv > /dev/null; then
    export PLENV_ROOT="\${HOME}/.plenv"
    export PATH=\${PLENV_ROOT}/shims:\${PATH}
    eval "\$(plenv init -)";
fi
_PLENVCONF_

% exec $SHELL -l

動作確認

  • インストール可能なバージョン一覧を表示
% plenv install -l
Available versions:
 5.6.0
 5.6.1-TRIAL1
 5.6.1-TRIAL2
 5.6.1-TRIAL3
 5.6.1
 5.6.2
 5.7.0
 5.7.1
 5.7.2
 5.7.3

...省略...

 5.19.1
 5.19.2
 5.19.3
 5.19.4
 5.19.5
 5.19.6
 5.19.7

plenvでPerlセットアップ

  • Perl 5.18.0 をセットアップ
% plenv install 5.18.0
Fetching 5.18.0 as /Users/ysaotome/.plenv/cache/perl-5.18.0.tar.bz2 (http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/perl-5.18.0.tar.bz2)

...省略...

ln -fs /Users/ysaotome/.plenv/versions/5.18.0/bin/s2p5.18.0 /Users/ysaotome/.plenv/versions/5.18.0/bin/s2p
ln -fs /Users/ysaotome/.plenv/versions/5.18.0/bin/shasum5.18.0 /Users/ysaotome/.plenv/versions/5.18.0/bin/shasum
ln -fs /Users/ysaotome/.plenv/versions/5.18.0/bin/splain5.18.0 /Users/ysaotome/.plenv/versions/5.18.0/bin/splain
ln -fs /Users/ysaotome/.plenv/versions/5.18.0/bin/xsubpp5.18.0 /Users/ysaotome/.plenv/versions/5.18.0/bin/xsubpp
ln -fs /Users/ysaotome/.plenv/versions/5.18.0/bin/zipdetails5.18.0 /Users/ysaotome/.plenv/versions/5.18.0/bin/zipdetails
  • Perl 5.19.7 をセットアップ
% plenv install 5.19.7
Fetching 5.19.7 as /Users/ysaotome/.plenv/cache/perl-5.19.7.tar.bz2 (http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/perl-5.19.7.tar.bz2)

...省略...


ln -fs /Users/ysaotome/.plenv/versions/5.19.7/bin/s2p5.19.7 /Users/ysaotome/.plenv/versions/5.19.7/bin/s2p
ln -fs /Users/ysaotome/.plenv/versions/5.19.7/bin/shasum5.19.7 /Users/ysaotome/.plenv/versions/5.19.7/bin/shasum
ln -fs /Users/ysaotome/.plenv/versions/5.19.7/bin/splain5.19.7 /Users/ysaotome/.plenv/versions/5.19.7/bin/splain
ln -fs /Users/ysaotome/.plenv/versions/5.19.7/bin/xsubpp5.19.7 /Users/ysaotome/.plenv/versions/5.19.7/bin/xsubpp
ln -fs /Users/ysaotome/.plenv/versions/5.19.7/bin/zipdetails5.19.7 /Users/ysaotome/.plenv/versions/5.19.7/bin/zipdetails
  • セットアップ結果を確認
% plenv versions
* system (set by /Users/ysaotome/.plenv/version)
  5.18.0
  5.19.7

pyenv + virtualenvを使ってみよう

Python 3.3.3 と tornado が使える専用環境を作ってみる

  • Python 3.3.3 で動作する環境 tornado-py333 を作成する
% pyenv virtualenv 3.3.3 tornado-py333
Installing setuptools from https://bitbucket.org/pypa/setuptools/raw/0.7.4/ez_setup.py...

...省略...

    warning: no previously-included files matching '*.rst' found under directory 'docs/_build'
    no previously-included directories found matching 'docs/_build/_sources'
    Installing pip3 script to /Users/ysaotome/.pyenv/versions/tornado-py333/bin
    Installing pip3.3 script to /Users/ysaotome/.pyenv/versions/tornado-py333/bin
    Installing pip script to /Users/ysaotome/.pyenv/versions/tornado-py333/bin
Successfully installed pip
Cleaning up...
  • 確認
% pyenv versions
* system (set by /Users/ysaotome/.pyenv/version)
  2.7.6
  3.3.3
  pypy-2.2.1
  tornado-py333
  • tornado-py333 に tornado をセットアップ
    • tmp001 フォルダを作成し、そのフォルダ配下を tornado-py333 を利用する環境とする
% mkdir ~/tmp001
% cd ~/tmp001
% pyenv local tornado-py333
% pyenv rehash
% pyenv versions
  system
  2.7.6
  3.3.3
  pypy-2.2.1
* tornado-py333 (set by /Users/ysaotome/tmp001/.python-version)
%
% pip list
pip (1.5)
setuptools (0.7.4)
%
% pip install tornado
Downloading/unpacking tornado
  Downloading tornado-3.1.1.tar.gz (374kB): 374kB downloaded
  Running setup.py (path:/Users/ysaotome/.pyenv/versions/tornado-py333/build/tornado/setup.py) egg_info for package tornado

    warning: no previously-included files matching '_auto2to3*' found anywhere in distribution
Installing collected packages: tornado
  Running setup.py install for tornado

    warning: no previously-included files matching '_auto2to3*' found anywhere in distribution
Successfully installed tornado
Cleaning up...
% pip list
pip (1.5)
setuptools (0.7.4)
tornado (3.1.1)
  • これで tmp001 配下に専用の tornado 環境をセットアップできました

  • 環境が不要になったら tornado-py333 を削除すれば元通りです

% pyenv uninstall tornado-py333
pyenv: remove /Users/ysaotome/.pyenv/versions/tornado-py333? y
%
% pyenv versions
pyenv: version `tornado-py333' is not installed
  system
  2.7.6
  3.3.3
  pypy-2.2.1
%
% pyenv local --unset
% pyenv versions
* system (set by /Users/ysaotome/.pyenv/version)
  2.7.6
  3.3.3
  pypy-2.2.1

rbenv + gemsetを使ってみよう

Ruby 2.0.0-p353 と Rails 4 が使える専用環境を作ってみる

  • Ruby 2.0.0-p353 で動作する環境 Rails-rb2p353 を作成する
% rbenv gemset create 2.0.0-p353 Rails-rb2p353
created Rails-rb2p353 for 2.0.0-p353
  • 確認
% rbenv gemset list
2.0.0-p353:
  Rails-rb2p353
  • Rails-rb2p353 に Rails 4 をセットアップ
    • tmp001 フォルダを作成し、そのフォルダ配下を Rails-rb2p353 を利用する環境とする
% mkdir ~/tmp001
% cd ~/tmp001
% rbenv gemset active
no active gemsets
% echo 'Rails-rb2p353' > .rbenv-gemset
% rbenv gemset active
Rails-rb2p353 global
%
% rbenv local 2.0.0-p353
% rbenv rehash
% rbenv versions
  system
  1.9.3-p484
* 2.0.0-p353 (set by /Users/ysaotome/tmp001/.ruby-version)
%
% gem list

*** LOCAL GEMS ***

% gem install rails
Fetching: i18n-0.6.9.gem (100%)
Successfully installed i18n-0.6.9

...省略...

unable to convert "\x80" from ASCII-8BIT to UTF-8 for guides/assets/images/tab_yellow.gif, skipping
unable to convert "\x89" from ASCII-8BIT to UTF-8 for guides/assets/images/tab_yellow.png, skipping
unable to convert "\xFF" from ASCII-8BIT to UTF-8 for guides/assets/images/vijaydev.jpg, skipping
1 gem installed
%
% gem list

*** LOCAL GEMS ***

actionmailer (4.0.2)
actionpack (4.0.2)
activemodel (4.0.2)
activerecord (4.0.2)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.2)
arel (4.0.1)
atomic (1.1.14)

...省略...

rack (1.5.2)
rack-test (0.6.2)
rails (4.0.2)
railties (4.0.2)
rake (0.9.6)
rdoc (4.0.0)
sprockets (2.10.1)
sprockets-rails (2.0.1)
test-unit (2.0.0.0)
thor (0.18.1)
thread_safe (0.1.3)
tilt (1.4.1)
treetop (1.4.15)
tzinfo (0.3.38)
  • これで tmp001 配下に専用の Rails 4 環境をセットアップできました

  • 環境が不要になったら Rails-rb2p353 を削除すれば元通りです

% rbenv gemset delete 2.0.0-p353 Rails-rb2p353
deleted Rails-rb2p353 from 2.0.0-p353
%
% rbenv gemset file
/Users/ysaotome/tmp001/.rbenv-gemsets
% rm -rf .rbenv-gemsets
%
% rbenv versions
  system
  1.9.3-p484
* 2.0.0-p353 (set by /Users/ysaotome/tmp001/.ruby-version)
%
% rbenv local --unset
% rbenv versions
* system (set by /Users/ysaotome/.rbenv/version)
  1.9.3-p484
  2.0.0-p353
%

plenv + pmsetを使ってみよう

Perl 5.19.7 と Mojolicious が使える専用環境を作ってみる

  • Perl 5.19.7 で動作する環境 mojo-pl5197 を作成する
% plenv pmset create 5.19.7 mojo-pl5197
created mojo-pl5197 for 5.19.7
  • 確認
% plenv pmset list
5.19.7:
  mojo-pl5197
  • mojo-pl5197 に Mojolicious をセットアップ
    • tmp001 フォルダを作成し、そのフォルダ配下を mojo-pl5197 を利用する環境とする
    • 途中 plenv install-cpanm コマンドで、パッケージ管理ツール cpanm をセットアップしている
% mkdir ~/tmp001
% cd ~/tmp001
% plenv pmset active
no active pmsets
% echo 'mojo-pl5197' > .plenv-pmsets
% rbenv gemset active
mojo-pl5197
%
% plenv local 5.19.7
% plenv rehash
% plenv versions
  system
  5.18.0
* 5.19.7 (set by /Users/ysaotome/tmp001/.perl-version)
%
% plenv install-cpanm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   303    0   303    0     0    406      0 --:--:-- --:--:-- --:--:--   406
100  262k  100  262k    0     0   153k      0  0:00:01  0:00:01 --:--:--  595k
--> Working on App::cpanminus
Fetching http://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7001.tar.gz ... OK
Configuring App-cpanminus-1.7001 ... OK
==> Found dependencies: Module::Build
--> Working on Module::Build
Fetching http://www.cpan.org/authors/id/L/LE/LEONT/Module-Build-0.4203.tar.gz ... OK
==> Found dependencies: Module::Build
Configuring Module-Build-0.4203 ... OK
Building and testing Module-Build-0.4203 ... OK
Successfully reinstalled Module-Build-0.4203
Building and testing App-cpanminus-1.7001 ... OK
Successfully installed App-cpanminus-1.7001
2 distributions installed
%
% plenv list-modules
App::cpanminus
Module::Build
Perl
%
% plenv exec cpanm Mojolicious
--> Working on Mojolicious
Fetching http://www.cpan.org/authors/id/S/SR/SRI/Mojolicious-4.66.tar.gz ... OK
Configuring Mojolicious-4.66 ... OK
Building and testing Mojolicious-4.66 ...
OK
Successfully installed Mojolicious-4.66
1 distribution installed
%
% plenv list-modules
App::cpanminus
Module::Build
Mojolicious
Perl
  • これで tmp001 配下に専用の Mojolicious 4 環境をセットアップできました

  • 環境が不要になったら mojo-pl5197 を削除すれば元通りです

% plenv pmset delete 5.19.7 mojo-pl5197
deleted mojo-pl5197 from 5.19.7
%
% plenv pmset file
/Users/ysaotome/tmp001/.plenv-pmsets
% rm -rf .plenv-pmsets
%
% plenv versions
  system
  5.18.0
* 5.19.7 (set by /Users/ysaotome/tmp001/.perl-version)
%
% plenv local --unset
% plenv versions
* system (set by /Users/ysaotome/.plenv/version)
  5.18.0
  5.19.7
%

利用例

仮想マシンを用意してまで環境分離する必要が無い開発や、PelicanOctopressといった静的サイトジェネレータを動かす環境を構築する際に活用しています。


Comments