9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pyenvのbashrcで少しつまずいた

Last updated at Posted at 2018-12-30

今回新しいサーバが届きpyenvを入れた時少しつまずいたので忘備録.

pyenvを入れた

とりあえず,Linuxbrew(入れ方はこちら参照)を入れて下記コマンドでインストール

$ brew install pyenv

インストールが終了したら,その後,以下を実行

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc

これで基本的な設定はできたので,

source ~/.bashrc

で読みこむ.

$ pyenv versions
* system

確かに動いていることを確認.普通ならこれで大丈夫なはず.

再度ログインする

再度ログインした時に,最初下のような表示がでた.

Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.15.0-43-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

Last login: ***
No command 'pyenv' found, did you mean:
 Command 'p7env' from package 'libnss3-tools' (universe)
 Command 'pyvenv' from package 'python3-venv' (universe)
pyenv: command not found

なぜかpyenv: command not foundと出てしまった.確かに

$ which python
/path/.linuxbrew/bin/python

本体ならば.pyenv下のpython担っているはずだが,違う場所を見ている.ただ,

$ pyenv versions
* system

は普通に動く.そこでもう一度.bashrcを読み込んでみると.pyenv下のpythonを見る様になった.

$ source ~/.bashrc
$ which python
/path/.pyenv/shims/python

ただ,bashrcはログインするたびに読み込んでいるはず.ここでつまずいた.

解決策

わかってみると,そりゃ当たり前だ!という感じであった.無意識のうちに~/.profileが終わった後に~/.bashrcが実行されると思っていたが.~/.profileを見てみると

.profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
eval $(/path/.linuxbrew/bin/brew shellenv)

となっていた...!bashrcが先に実行されてしまっていた.これを順番を変えてあげて以下の様にする.

.profile
# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
eval $(/path/.linuxbrew/bin/brew shellenv)

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

これで解決.そりゃそうだよね...

9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?