UbuntuでPython 3.9のバージョンをインストールする方法を紹介します。
- Aptを利用してインストール
- Sourceをダウンロードしてインストール
- AlternativesにPythonのバージョン管理
1. Aptを利用してインストール
次のようなコマンドで必要なプログラムをインストールします。
$ sudo apt update
$ sudo apt install software-properties-common
次のコマンドでRepositoryを登録します。
$ sudo add-apt-repository ppa:deadsnakes/ppa
次のコマンドでPython 3.9をインストールします。
$ sudo apt install python3.9
次のコマンドで python 3.9
がインストールされてパスを確認することができます。
$ which python3.9
/usr/bin/python3.9
$ python3.9 --version
Python 3.9.6
2. Sourceをダウンロードしてインストール
まず、基本的なプログラムをインストールする必要があります。
$ sudo apt update
$ sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev
wegetに python 3.9
ソースを受けて構築します。
$ wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
$ tar -xf Python-3.9.1.tgz
$ cd Python-3.9.1
$ ./configure --enable-optimizations
$ make -j 12
ビルド完了後、次のコマンドでインストールをします。
$ sudo make altinstall
python 3.9
がインストールされたことを確認します。
$ python3.9 --version
Python 3.9.6
3. AlternativesにPythonのバージョン管理
alternativesを使用すると、pythonのバージョンの変更を容易に行うことができます。
たとえば、 python 3.9
を使用しているがpython 2.7
に変更をしたいときalternativesというツールがこれを容易にするのに役立ちます。
まず、alternativesにpythonを登録するために python 3.9
が実際どのpathにインストールすることを確認します。
$ which python3.9
/usr/bin/python3.9
以下のようなコマンドで python 3.9
をalternativeを登録することができます。
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 3
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python (python) in auto mode
alternativeの詳細設定方法は、UbuntuでPythonのバージョンを変更する方法を参照してください。
次のコマンドでpythonの基本的なバージョンを python 3.9
に設定しました。
$ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.9 3 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.6 2 manual mode
3 /usr/bin/python3.9 3 manual mode
Press <enter> to keep the current choice[*], or type selection number: 3
バージョンを確認してみると、pythonが python 3.9
に設定されたことを確認することができます。
$ python --version
Python 3.9.6
後でPythonのバージョンの変更が必要な場合は、以下のコマンドを用いて、バージョンを変更ください。
$ sudo update-alternatives --config python
参考
Related Posts
- Linux debファイルのインストール
- UbuntuにVMwareをインストールする
- [Ubuntu] VMwareからWindows 11をインストールする
- Vi/Vimから1行または複数行を削除する方法
- Vi/Vimで行番号を表示する
- Ubuntuでrarを解凍、解凍
- UbuntuでGoogleドライブを使用する(ローカルフォルダにマウント)
- [Ubuntu] apt-cache search、インストール可能なパッケージの検索
- Ubuntu - DNSキャッシュを削除する方法
- Ubuntuで利用可能なテキストエディタの紹介
- Ubuntu(Linux) - RAM(メモリ)サイズの確認
- Ubuntuでタイムゾーンを変更する
- Ubuntu(Linux)でAtom Text Editorをインストールする
- Ubuntu(Linux)でMicrosoft Edgeブラウザをインストールする方法
- Ubuntu(Linux)でSlackをインストールする方法
- Ubuntu(Linux)からVisual Studio Codeをインストールする
- Linux - ファイル、ディレクトリ削除コマンド(rm -rf、rmdir)
- Linux - ファイルが変更された日付/時刻を確認する方法
- Linux - touchでファイルを作成し、ファイルの日付/時刻を変更する
- Linux - Node.jsでHtmlファイルをローカルサーバーで実行する
- Linux - zip、unzipによる圧縮と解凍
- Ubuntu - Linuxカーネルを削除する方法
- UbuntuでRight ALTをハンヨンキーに変換する
- Linuxファイル権限の概要、およびアクセス権の変更
- Linux - Image resize、Format変更コマンド
- Ubuntu - Gradle最新バージョンをインストールする方法
- Ubuntu - Notepad ++のインストール方法
- Ubuntu - Python 3.9のインストール方法
- Ubuntu - Sublime Text 4のインストール方法
- Ubuntu - nodejs LTSは、最新バージョンのインストール
- Proxy環境でpipを使用する方法
- 最新のコードにアップデートするrepo syncコマンド
- Linux - ディレクトリの容量を確認
- Linux - IPアドレスを確認
- Linux - killコマンドで実行中のプロセスを終了