로그인
Sign in
Atachment
첨부 '1'
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
Extra Form

하나의 심볼릭 링크로 여러 개의 패키지 관리하기 - update-alternatives


1. 개 요

버전이 각기 다른 패키지에 대해서 동일한 심볼릭 링크를 사용해야 할 경우에 어떻게 해야 할까? 원하는 버전으로 실행하고자 한다면 매번 해당 버전으로 심볼릭 링크를 걸어주면 될 것입니다. 사용자가 아닌 여러 프로그램에서 각기 다른 버전을 사용한다면 사용자가 심볼릭 링크를 변경해 주지 않고서는 프로그램이 자동으로 적당한 버전으로 심볼릭 링크를 해 주기는 어렵습니다. 예를 들어 python을 생각해 보죠. 파이썬은 현재 pythion2버전과 python3 버전이 시스템에 동시에 깔려 있습니다.

alter_170956.jpg


파이썬이 현재 2버전으로 심볼릭링크되어 있는데, 다른 파이썬 프로그램이 3버전을 요구할 경우 python 명령이 실행되어질 때 2버전으로 동작하기 때문에 3버전으로 심볼릭 링크를 갱신해 주지 않는 한 오류가 발생될 수 있습니다. 여기서 딜레마가 발생할 수 있습니다. 스크립트로 3버전을 요구하는 프로그램에 대해서 3버전으로 심볼릭 링크 처리해 주면 동작하겠지만, 2버전을 요구하는 다른 프로그램에선 또 오류가 발생될 수 있습니다.


이러한 문제를 해결하기 위해서 고안된 것이 alternatives 도구로 데비안 리눅스에서 개발되었고, 넘버원 리눅스와 레드햇 리눅스 계열에서는 update-alternatives 명령을 사용하며 alternatives로 심볼릭링크되어 있으므로, 두 명령어중 한 명령으로 사용이 가능합니다. update-alternatives를 이용하면 여러 개의 패키지에 대해서 한 개의 심볼릭 링크를 통하여 관리할 수 있는 이점이 있는데, 오늘의 강좌에서는 이 명령어의 사용법에 대해서 알아보는 시간을 갖도록 하겠습니다.

2. Update-alternatives 사용법

 Usage: /usr/sbin/update-alternatives [<option> ...] <command>

Commands:
  --install <link> <name> <path> <priority>  [--slave <link> <name> <path>] ...
                                                        add a group of alternatives to the system.
  --remove <name> <path>      remove <path> from the <name> group alternative.
  --remove-all <name>               remove <name> group from the alternatives system.
  --auto <name>                          switch the master link <name> to automatic mode.
  --display <name>                      display information about the <name> group.
  --list <name>                             display all targets of the <name> group.
  --config <name>                       show alternatives for the <name> group and ask the
                                                        user to select which one to use.
  --set <name> <path>               set <path> as alternative for <name>.

<link> is the symlink pointing to /etc/alternatives/<name>.
<name> is the master name for this link group.
<path> is the location of one of the alternative target files.
<priority> is an integer; options with higher numbers have higher priority in
  automatic mode.

Options:
  --altdir <directory>                    change the alternatives directory.
  --admindir <directory>             change the administrative directory.
  --verbose                                     verbose operation, more output.
  --quiet                                          quiet operation, minimal output.
  --help                                            show this help message.
  --version                                       show the version.



1. 심볼릭링크 생성(--install)

  update-alternatives --install <link> <name> <path> <priority>  [--slave <link> <name> <path>] ...

 <link>

 심볼릭링크명이 위치할 경로명

 <name>

 /etc/alternatives 경로에 위치할 심볼릭링크명

 <path>

 패키지가 설치되어 있는 경로

 <priority>

 자동모드로 동작할 때 동작할 우선 순위


예제로 NVidia 그래픽 카드 드라이버의 ld.so.conf 에 대해서 gl_conf로 심볼릭 링크를 생성해 봅니다. 먼저 기존 심볼릭 링크를 제거하고 새로 생성해 봅니다.

 # update-alternatives --remove gl_conf /etc/nvidia-current/ld.so.conf

 # update-alternatives --remove gl_conf /etc/nvidia340/ld.so.conf

 # update-alternatives --remove gl_conf /etc/nvidia304/ld.so.conf


자, 그러면 다음과 같이 nvidia-current(nvidia 390 드라이버)의 ld.so.conf에 대해서 gl_conf로 심볼릭 링크를 추가합니다. 

 # update-alternatives --install /etc/alternatives/ld.so.conf  gl_conf /etc/nvidia-current/ld.so.conf 500


그 다음에도 nvidia340, nvidia304에 대해서 다음과 같이 심볼릭 링크를 합니다.

 # update-alternatives --install /etc/alternatives/ld.so.conf gl_conf /etc/nvidia340/ld.so.conf 400

 # update-alternatives --install /etc/alternatives/ld.so.conf gl_conf /etc/nvidia304/ld.so.conf 300


2. 심볼릭링크 수동모드및 확인(--config)

 update-alternatives --config <name>


여러 개의 패키지에 대해서 alternatives로 심볼릭링크를 걸어 놓았을 때 심볼릭링크 상태를 확인하거나 심볼릭링크 우선순위를 변경하고자 할 때는 --config 옵션을 사용합니다. 그러면 이 옵션을 사용하여 엔비디아 그래픽 카드의 ld.so.conf 파일에 대한 심볼릭 링크 목록을 확인해 봅니다.

 # update-alternatives --config gl_conf

 There are 4 programs which provide `gl_conf'.

  Selection    Command
-----------------------------------------------
*+    1        /etc/ld.so.conf.d/GL/standard.conf
        2        /etc/nvidia-current/ld.so.conf
        3        /etc/nvidia340/ld.so.conf
        4        /etc/nvidia304/ld.so.conf
Enter to keep the default[*], or type selection number:


네 개의 목록이 있습니다. 앞서 심볼릭링크를 추가할 때 nvidia-current를 500, nvidia340은 400, nvidia304은 300으로 우선순위도를 지정해 주었는데, 숫자가 높을수록 우선순위도가 높습니다. 현재 시스템에서 기본적으로 설정되어 있는 1번이 가장 높은 우선순위도로 되어 있습니다. 그러면 /etc/alternatives/gl_conf 심볼릭 링크의 상태를 확인해 봅니다.

 # ll /etc/alternatives/gl_conf
 lrwxrwxrwx 1 root root 34  4월 16 17:55 /etc/alternatives/gl_conf -> /etc/ld.so.conf.d/GL/standard.conf


현재 /etc/ld.so.conf.d/GL/standard.conf 파일이 gl_conf로 심볼릭링크되어 있습니다. 그러면 --config 옵션을 넣어 실행하여 기본값으로 3를 입력해 봅니다.

 # update-alternatives --config gl_conf

 There are 4 programs which provide `gl_conf'.

  Selection    Command
-----------------------------------------------
*+    1        /etc/ld.so.conf.d/GL/standard.conf
        2        /etc/nvidia-current/ld.so.conf
        3        /etc/nvidia340/ld.so.conf
        4        /etc/nvidia304/ld.so.conf

 Enter to keep the default[*], or type selection number:3

 Using `/etc/nvidia340/ld.so.conf' to provide `gl_conf'.

# ll /etc/alternatives/gl_conf
 lrwxrwxrwx 1 root root 25  4월 16 18:06 /etc/alternatives/gl_conf -> /etc/nvidia340/ld.so.conf


gl_conf 심볼릭링크가 /etc/nvidia340/ld.so.conf로 변경되었음을 확인할 수 있습니다. 이렇게 --config 옵션을 사용하여 수동으로 원하는 파일로 심볼릭링크를 갱신할 수 있습니다.


3. 자동 모드 (--auto)

  update-alternatives --auto <name>


자동모드는 우선순위도 값에 따라서 심볼릭링크가 결정되는데, 제일 높은 값이 먼저 선택되며, 자동으로 선택된 링크가 제거되면 다음 낮은 순위로 심볼릭링크가 갱신됩니다. 즉 세개의 엔비디아 그래픽 카드 드라이버만 있을 경우에 제일 순위도가 높은 dkms-nvidia-current 패키지가 제거되면 자동으로 dkms-nvidia-340 패키지가 gl_conf로 심볼릭링크 되는 것입니다.


4. 심볼릭링크 제거(--remove)

 update-alternatives --remove <name> 경로명/파일명


이 옵션에 대해서는 --install 옵션에 살펴보았듯이, 삭제하고자 하는 심볼릭링크 대상파일명을 지정해서 제거하면 됩니다.

5. 심볼릭링크 목록 확인( --display)

 update-alternatives --display <name>


alternatives로 설정된 심볼릭링크 목록을 확인하고자 할 때는 --display 옵션을 사용합니다.

 # update-alternatives --display gl_conf
 gl_conf - status is manual.
   link currently points to /etc/nvidia340/ld.so.conf
 /etc/ld.so.conf.d/GL/standard.conf - priority 500
    slave xorg_extra_modules: /usr/lib64/xorg/xorg-1.6-extra-modules
 /etc/nvidia-current/ld.so.conf - priority 500
 /etc/nvidia340/ld.so.conf - priority 400
 /etc/nvidia304/ld.so.conf - priority 300
 Current `best' version is /etc/ld.so.conf.d/GL/standard.conf.

--list 옵션을 사용하여 간단하게 심볼릭링크 목록을 확인할 수도 있습니다.

 # update-alternatives --list gl_conf
 /etc/ld.so.conf.d/GL/standard.conf
 /etc/nvidia-current/ld.so.conf
 /etc/nvidia340/ld.so.conf
 /etc/nvidia304/ld.so.conf


6. 심볼릭링크 변경하기(--set)

  update-alternatives --set <name> <path>


--config 옵션으로 심볼릭링크를 변경하는 방법에 대해서 알아 보았는데, --config 옵션은 목록을 확인하여 원하는 대상으로 심볼릭링크를 거는 것에 비해 --set 옵션은 심볼릭링크 목록을 알고 있는데 상태에서 바로 원하는 대상으로 심볼릭링크를 갱신하고자 할 때 사용됩니다. --config 옵션은 스크립트에 적용하기 어려우나, 이 옵션은 스크립트내에선 유용합니다.


  # update-alternatives --set gl_conf /etc/nvidia-current/ld.so.conf

  Using `/etc/nvidia-current/ld.so.conf' to provide `gl_conf'.


3. 연습해 보기

앞서 머릿말에서 파이썬을 예제로 들었는데, python 2버전과 3버전을 python으로 심볼릭링크명을 갖도록 설정하여 버전을 요구하는 프로그램에 따라서 심볼릭링크를 갱신하도록 연습해 보기 바랍니다.



























 # rm -f python

 # alternatives --install /usr/bin/python python /usr/bin/python2 200

 # alternatives --install /usr/bin/python python /usr/bin/python3 100

 # alternatives --set python /usr/bin/python3

 # ll /etc/alternatives/py*
 lrwxrwxrwx 1 root root 16  4월 16 18:44 /etc/alternatives/python -> /usr/bin/python3*

 # alternatives --set python /usr/bin/python2

 # ll /etc/alternatives/py*
 lrwxrwxrwx 1 root root 16  4월 16 18:44 /etc/alternatives/python -> /usr/bin/python2*




List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 넘버원 리눅스 팁은 FAQ 게시판으로 zharyong 2018.07.16 808
209 시스템 [시스템] rpm 패키지는 어떻게 푸나? How to extract RPM package dir... file zharyong 2018.05.27 1255
208 인터넷 [No1.Linux 2018] 공인 인증서 적용 사이트 안내 [No1.Linux 2018 SE] 공인 인증서 적용 사이트 1. 개 요 앞 서 은행에서 공인 인증서로 인터넷 뱅킹을 하는 방법에 대해서 알아보았고... 1 zharyong 2018.05.17 738
207 인터넷 [No1.Linux 2018] 주요 은행의 인터넷 뱅킹 1 file zharyong 2018.05.17 4049
206 더욱 더 편리해진 넘버원리눅스 2019의 강력한 인터넷뱅킹 지원성 2 file zharyong 2018.05.17 14362
205 TodayAPP [Today'sAPP] 내 컴퓨터의 하드웨어 정보를 DB에 등록하고 열람해 보자. file zharyong 2018.05.11 388
204 시스템 [팁] xterm-256color': unknown terminal type 메시지및 MC에서 키보드 사... xterm-256color': unknown terminal type 대책및 MC에서 일부 키보드 사용이 안될 때 버전이 서로 다른 원격 No1.Linux 서버에 접속하... zharyong 2018.05.04 823
203 시스템 [MC] No1.Linux 2018 SE의 mc에서 ISO 파일 내용물을 보려면 file zharyong 2018.05.03 318
202 시스템 [컴파일오류] /usr/bin/ld: cannot find -lgtk-3 컴파일 오류 : /usr/bin/ld: cannot find -lgtk-3에 대한 대책 소스를 컴파일하다보면 다음과 같이 라이브러리 링크 문제가 발생되는 경우가... zharyong 2018.05.01 9601
201 스크립트 [팁] No1.Linux 2018 SE 버전의 부팅시 하드 디스크 자동 마운트 file zharyong 2018.05.01 362
200 엑스 [한글입력기] No1.Linux 2018 SE 한글입력기 2 file zharyong 2018.04.30 3217
199 인터넷 [네트워크] 비번 없이 SSH 서버에 자동 로그인 하기 SSH 서버에 비밀번호 입력없이 자동 로그인하기 1. 개 요 신뢰성이 있는 원격 SSH 서버에 자주 접속하는 경우에 비밀번호를 입력하여 ... zharyong 2018.04.25 609
198 하드웨어 [하드웨어] 블루투쓰 USB 동글 동작하지 않을 경우 file zharyong 2018.04.25 2729
197 시스템 [시스템] 쉘에서 set GTK_DEBUG 관련 오류 메시지가 발생되는 경우 file zharyong 2018.04.24 370
196 [네트워크] 리얼텍 r8168 모듈로 이더넷에 장애가 있을 경우 Realtek 유선이더넷 장치에 문제가 있는 경우 넘버원 리눅스 2018 SE 버전에서 r8168 모듈을 사용하는 이더넷 네트워크 카드 가운데 r8168... zharyong 2018.04.19 1679
195 시스템 [시스템] DKMS(Dynamic Kernel Module Support)를 이용한 모듈 관리 DKMS(Dynamic Kernel Module Support) 모듈 관리 1. 개 요 DKMS(Dynamic Kernel Module Support)는 커널 모듈이 부팅시 생성되고, 활성... zharyong 2018.04.17 4751
» 시스템 [시스템] Alternatives(Update-altenatives)로 하나의 심볼릭 링크로 여러 패... 하나의 심볼릭 링크로 여러 개의 패키지 관리하기 - update-alternatives 1. 개 요 버전이 각기 다른 패키지에 대해서 동일한 심볼릭 링크... file zharyong 2018.04.17 5849
193 TodayAPP [TodayAPP] 윈도의 캡쳐도구와 유사한 기능의 Ksnip file zharyong 2018.04.15 619
192 스크립트 [스크립트] 이제 카카오톡 설치가 매우 쉬어졌어요! - kakaoinst 1 file zharyong 2018.04.14 10947
191 TodayAPP [TodayAPP] USB 메모리를 빠르게 포맷해 주는 Quick USB Formatter file zharyong 2018.04.14 342
190 활용 [활용] 파이어폭스 스크린샷 기능 및 날씨 보기 file zharyong 2018.04.14 328
목록
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 13 Next
/ 13