JHH9232 Blog

update-alternatives 로 패키지의 여러 버전을 관리해보자


|

목차


개요

Java 든 Python이든 gcc, g++이든 하나의 OS에서 여러가지 버전의 프로그램을 사용하고 싶을 때가 있다.
이럴 때는 update-alternatives 를 사용하면 편하다.

방법

추가

sudo update-alternatives --install [링크] [이름] [실행 파일] [우선 순위]

예제

  • python3 버전 관리
update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.7 2
  • gcc 버전 관리
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 1
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 2

삭제

sudo update-alternatives --remove [이름] [실행 파일]

예제

  • python3.7 삭제
update-alternatives --remove gcc /usr/local/bin/python3.7
  • gcc-8 삭제
update-alternatives --remove gcc /usr/bin/gcc-8

설정

사용할 버전의 selection을 입력하면 된다.

sudo update-alternatives --config [이름]

예제

  • python3 버전 설정
update-alternatives --config python3
Copy
There are 3 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                      Priority   Status
------------------------------------------------------------
  0            /usr/local/bin/python3.7   3         auto mode
  1            /usr/bin/python3.10        2         manual mode
  2            /usr/local/bin/python3.5   1         manual mode
* 3            /usr/local/bin/python3.7   3         manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
  • gcc 버전 설정
update-alternatives --config gcc

There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path            Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-7   2         auto mode
  1            /usr/bin/gcc-7   2         manual mode
* 2            /usr/bin/gcc-8   1         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

Comments