본문 바로가기

리눅스

Ubuntu 18.04 LTS에서 Python 3.9으로 업그레이드하는 방법

반응형

Ubuntu 18.04 LTS에서 Python 3.9으로 업그레이드하는 방법

테스트 환경

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

$ getconf LONG_BIT
64
  • 시스템에 설치된 파이썬 버전 확인
python --version
$ python --version
Python 3.6.9
  • 데드스네이크(deadsnakes repository) 저장소 추가 및 업데이트
sudo add-apt-repository ppa:deadsnakes/ppa
$ add-apt-repository ppa:deadsnakes/ppa
 This PPA contains more recent Python versions packaged for Ubuntu.

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

Update Note
===========
Please use this repository instead of ppa:fkrull/deadsnakes.

Reporting Issues
================

Issues can be reported in the master issue tracker at:
https://github.com/deadsnakes/issues/issues

Supported Ubuntu and Python Versions
====================================

- Ubuntu 18.04 (bionic) Python2.3 - Python 2.6, Python 3.1 - Python 3.5, Python3.7 - Python3.11
- Ubuntu 20.04 (focal) Python3.5 - Python3.7, Python3.9 - Python3.11
- Note: Python2.7 (all), Python 3.6 (bionic), Python 3.8 (focal) are not provided by deadsnakes as upstream ubuntu provides those packages.
- Note: for focal, older python versions require libssl1.0.x so they are not currently built

The packages may also work on other versions of Ubuntu or Debian, but that is not tested or supported.
  • 패키지 목록 업데이트
sudo apt-get update
$ apt-get update
...
Hit:5 http://kr.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:6 http://kr.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:7 http://kr.archive.ubuntu.com/ubuntu bionic-security InRelease
728x90

 

  • python 3.9 패키지 설치
apt-get install -y python3.9
$ apt-get install python3.9
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm9
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libpython3.9-minimal libpython3.9-stdlib python3.9-minimal
Suggested packages:
  python3.9-venv binfmt-support
The following NEW packages will be installed:
  libpython3.9-minimal libpython3.9-stdlib python3.9 python3.9-minimal
0 upgraded, 4 newly installed, 0 to remove and 4 not upgraded.
Need to get 4,893 kB of archives.
After this operation, 19.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...
  • update-alternatives 명령어로 Python 3.9을 기본 Python 버전으로 설정
    • 이전 python 버전과 신규 python 버전을 update-alternatives 명령으로 추가
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
$ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python3 (python3) in auto mode
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
$ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
update-alternatives: using /usr/bin/python3.9 to provide /usr/bin/python3 (python3) in auto mode
  • python default version 업데이트
    • python 3.9를 가리키도록 python 3 업데이트
update-alternatives --config python3
$ update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.9   2         auto mode
  1            /usr/bin/python3.6   1         manual mode
  2            /usr/bin/python3.9   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
  • python version
python --version
$ python --version
Python 3.9.12
  • pip install(pip3 install)
sudo apt install -y python3-pip python3.9-distutils
  • pip version
pip --version
$ pip --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.9)

 

728x90
반응형