python3 설치 및 버전 변경 방법 개요

- UbuntuOS에서 python3 설치, 버전확인, python 명령어로 연결하는 방법 소개

테스트 수행한 환경

- 인터넷가능한 환경, ubuntu 22.04

1. ubuntu 에서 python3 설치 방법

1) apt update

root@ubuntuserver2204:~# apt update
생략..
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done

2) python3 설치하기

- 끝에 -y 옵션을 넣으면 Y/N 묻지 않고 바로 설치 진행

root@ubuntuserver2204:~# apt install python3 -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libpython3-stdlib libpython3.10 libpython3.10-minimal libpython3.10-stdlib python3-minimal python3.10 python3.10-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.10-venv python3.10-doc binfmt-support
The following packages will be upgraded:
  libpython3-stdlib libpython3.10 libpython3.10-minimal libpython3.10-stdlib python3 python3-minimal python3.10 python3.10-minimal
8 upgraded, 0 newly installed, 0 to remove and 180 not upgraded.
생략.. 

3) 현재 OS에서 설정된 python, python3 version 확인

- python 명령으로는 실행이 안되고, python3 or python3.10 으로 실행해야 한다.
- 해당방법이 불편하지 않으면 그대로 사용하면되고, python 명령어로 연결하고 싶으면 이후 단계 진행

root@ubuntuserver2204:~# python --version
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3

root@ubuntuserver2204:~# python3 --version
Python 3.10.6

root@ubuntuserver2204:~# python3.10 --version
Python 3.10.6

2. python실행시 python3가 실행되도록 설정

방법1. python-is-python3 이용( 특정버전 이상부터 동작)

root@ubuntuserver2204:~# apt install python-is-python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  python-is-python3
0 upgraded, 1 newly installed, 0 to remove and 180 not upgraded.
이후 생략..

방법2. alias를 이용하여 설정하는 방법

## .bashrc 에 아래 문장추가
root@ubuntuserver2204:~# vi .bashrc
alias python=python3

## .bashrc 실행하여 적용
root@ubuntuserver2204:~# source ~/.bashrc

설정적용이후 현재 OS에서 설정된 python, python3 version 재확인

root@ubuntuserver2204:~# python --version
Python 3.10.6

root@ubuntuserver2204:~# python3 --version
Python 3.10.6

root@ubuntuserver2204:~# python3.10 --version
Python 3.10.6

root@ubuntuserver2204:~# which python
/usr/bin/python

root@ubuntuserver2204:~# which python3
/usr/bin/python3

root@ubuntuserver2204:~# ll /usr/bin/python
lrwxrwxrwx 1 root root 7 Oct 11  2021 /usr/bin/python -> python3*

태그: ,

카테고리:

업데이트:

댓글남기기