- 1. 概要
- 2. 準備
- 3. インストール
- 4. 展開
- 5. 参考サイト
1. 概要
「Ubuntu 22.04」にインストールする機会があったので、記録を残します。
通常は、「apt」コマンドで、インストールするのですが、事情があって、バイナリをインストールします。
2. 準備
「python」をインストールするのに必要なパッケージがあります。
一時的にこれだけは、「apt」でインストールします。
「root」ユーザ権限で。
apt install -y clang make libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev liblzma-dev
3. インストール
いよいよ、「python」をインストールします。
この時点で、安定版とみえる、「3.12.4」をインストールします。
まずは、「pyenv」から。
ログインユーザで。
curl https://pyenv.run | bash
下記のようなメッセージが表示されます。
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 270 100 270 0 0 455 0 --:--:-- --:--:-- --:--:-- 455
Cloning into '/home/hogehoge/.pyenv'...
remote: Enumerating objects: 1448, done.
remote: Counting objects: 100% (1448/1448), done.
remote: Compressing objects: 100% (722/722), done.
remote: Total 1448 (delta 903), reused 903 (delta 593), pack-reused 0 (from 0)
Receiving objects: 100% (1448/1448), 1.17 MiB | 6.43 MiB/s, done.
Resolving deltas: 100% (903/903), done.
Cloning into '/home/hogehoge/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (11/11), 38.72 KiB | 197.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/hogehoge/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (10/10), done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/hogehoge/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (57/57), done.
remote: Total 64 (delta 10), reused 23 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (64/64), 43.19 KiB | 1.73 MiB/s, done.
Resolving deltas: 100% (10/10), done.
WARNING: seems you still have not added 'pyenv' to the load path.
# Load pyenv automatically by appending
# the following to
# ~/.bash_profile if it exists, otherwise ~/.profile (for login shells)
# and ~/.bashrc (for interactive shells) :
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init - bash)"
# Restart your shell for the changes to take effect.
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:
eval "$(pyenv virtualenv-init -)"
vi ~/.bashrc
末尾に下記を記述します。
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
反映して。
source ~/.bashrc
「python」本体のインストール。
pyenv install 3.12.4
下記のようなメッセージが表示されます。
Downloading Python-3.12.4.tar.xz...
-> https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tar.xz
Installing Python-3.12.4...
Installed Python-3.12.4 to /home/hogehoge/.pyenv/versions/3.12.4
バージョン設定を行います。
pyenv global 3.12.4
4. 展開
システム全体で、有効となるように展開します。
sudo mkdir -pv /opt/python
sudo cp -a ~/.pyenv/versions/3.12.4/* /opt/python/
各ユーザで。
echo 'export PATH=/opt/python/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
逆に、前項で記述した、下記の行は削除します。
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
5. 参考サイト
本ページは、「ChatGPT」くんを参考にさせていただきました。
|