1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntuで異なるバージョンのPythonをインストールする

Posted at

Ubuntu22.04/24.04 で異なるバージョンのPythonをインストールする

概要

Pythonを使って開発をしている時に複数のバージョンを切り替えながら使用することはよくあると思います。今回はUbuntu 22.04、24.04 環境に別バージョンのPythonをインストールする手順についてまとめてみました。

Ubuntuに標準インストールされているPythonバージョン

Ubuntu 22.04と24.04で追加のリポジトリ設定なしでインストール可能なPythonバージョンは下記の通りです。

Pythonバージョン Ubuntu 22.04 Ubuntu 24.04
Python 3.9 × ×
Python 3.10 ×
Python 3.11 × ×
Python 3.12 ×

注意点:

  • Ubuntu 22.04ではPython 3.10がデフォルトでプリインストール
  • Ubuntu 24.04ではPython 3.12がデフォルトでプリインストール
  • その他のバージョンをインストールする場合は、Deadsnakes PPAの追加が必要

共通するPPAの設定

標準インストールされていないバージョンをインストールしたい場合、PPAを使用してインストールする必要があります。下記コマンドを使用してPPA設定を実施します。

sudo apt update
sudo apt upgrade -y
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

Ubuntu 22.04/24.04環境にPythonをインストールする

Python 3.9 (Ubuntu 22.04/24.04環境共通)

下記コマンドを使用してインストールします。

sudo apt install python3.9

必要に応じて下記も設定します。

python3.9-venv python3.9-dev python3.9-distutils

Python 3.10 (Ubuntu 24.04環境のみ)

下記コマンドを使用してインストールします。

sudo apt install python3.10

必要に応じて下記も設定します。

python3.10-venv python3.10-dev python3.10-distutils

Python 3.11 (Ubuntu 22.04/24.04環境共通)

下記コマンドを使用してインストールします。

sudo apt install python3.11

必要に応じて下記も設定します。

python3.11-venv python3.11-dev python3.11-distutils

Python 3.12 (Ubuntu 22.04環境のみ)

下記コマンドを使用してインストールします。

sudo apt install python3.12

必要に応じて下記も設定します。

python3.12-venv python3.12-dev python3.12-distutils

まとめ

標準でインストールされているバージョンがわからなかったので、調べるついでに設定方法をまとめてみました。開発環境でいろいろなバージョンを切り替えて使用することがあると思いますので、どなたかの参考に立てれば幸いです。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?