Help us understand the problem. What is going on with this article?

homeにgolang, direnv とvirtualenvを入れて動かす

More than 5 years have passed since last update.

概要

さくらレンタルサーバー(FreeBSD)にて、homeディレクトリにgoとdirenvを入れて、direnvでvirtualenvを動かすようにしたのでメモ。

環境
FreeBSD 9.1-RELEASE-p15 amd64
プラン さくらのレンタルサーバ スタンダード

手順

環境変数

export MYBASE='usr'

export LOCALBASE=${HOME}/${MYBASE}/local
export PATH=${PATH}:${LOCALBASE}/bin

export GOROOT=${LOCALBASE}/go
export PATH=${PATH}:${GOROOT}/bin

golangをdownloadして$LOCALBASEに展開

01_go.sh
export OSNAME=$(tr '[A-Z]' '[a-z]' <<< $(uname -s))
export ARCHNAME='amd64'

export FILENAME=go1.4.${OSNAME}-${ARCHNAME}.tar.gz
export URL=http://golang.org/dl/

mkdir -p ${LOCALBASE}/{src,bin}
cd ${LOCALBASE}/src
curl -L ${URL}/${FILENAME} | tar xfz -
mv go ${LOCALBASE}/

direnvをdownloadして$LOCALBASE/binにインストール

02_direnv.sh
cd ${LOCALBASE}
git clone https://github.com/zimbatm/direnv.git
cd direnv
DESTDIR=${LOCALBASE} make install

以上でbash_profileなどに

export MYBASE='usr'
export LOCALBASE=${HOME}/${MYBASE}/local
export PATH=${PATH}:${LOCALBASE}/bin
export GOROOT=${LOCALBASE}/go
export PATH=${PATH}:${GOROOT}/bin
eval "$(direnv hook bash)"

などと加えれば、direnvが動き、各ディレクトリの.envrcを読み込むようになる。

direnvでvirtualenv

virtualenvを$LOCALBASE/binにインストール

03_virtualenv.sh
cd ${LOCALBASE}/src
curl -L https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.11.6.tar.gz | tar xfz -
cd virtualenv-1.11.6
python setup.py build
mv build/lib/* ${LOCALBASE}/bin

以上で、以下のように.envrcを書いたディレクトリに移動すると、そのディレクトリに.direnv/virtualenvが作成される。

.envrc
WORK_DIR_NAME=.direnv/virtualenv
if ! [ -d $WORK_DIR_NAME ]; then
  virtualenv.py --no-site-packages --distribute $WORK_DIR_NAME
  virtualenv.py --relocatable $WORK_DIR_NAME
fi
. $WORK_DIR_NAME/bin/activate

参考

zimbatm/direnv

aminamid
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした