개요

yum 은 Yellowdog Updater Modified 의 약자로 대화형 패키지 관리 시스템이다. wikipedia 에 따르면 Duke 대학교의 물리학과에서 사용하는 Red Hat Linux 시스템의 관리를 편하게 하기 위해 만들어 졌다고 한다.

Slackware 때 사용하던 .tgz 패키지에 비해 rpm 은 의존성 관리와 버전 관리라는 장점이 있었지만 실제 rpm 으로 Linux 시스템을 관리할 경우 다음과 같은 문제가 있었다.

  • 특정 rpm 에 의존성 있는 패키지가 있을 경우 일일이 다운받아서 의존성 있는 rpm을 설치해야 함.
  • rpm 이 update 됐을 경우  update 됐다는 사실을 알기가 어려움(패키지마다 직접 확인 필요)

yum 은 central repository 를 통해 rpm 을 배포하고 의존성 관리를 하므로 손쉽게 패키지를 관리할수 있다.


주요 명령어와 옵션

yum 은 command 와 option 으로 구성되어 있다. yum --help 로 전체 명령어와 옵션을 확인할 수 있다.

많이 쓰이는 options 는 다음과 같다.

--enablerepo=[repo]여러개의 yum repository가 있을 경우 사용할 repos 를 지정한다. * 같은 wildcard를 사용할 수 있다.
--disablerepo=[repo]사용하지 않을 repos 를 지정한다. wildcard 사용 가능
--nogpgcheckGPG 서명검증을 사용하지 않는다. 해당 repos 의 공개키가 없어서 서명검증에 실패할 경우에 사용한다.
-d [debug level]debugging level을 지정한다. 0 - 10 까지 가능하며 숫자가 클수록 자세한 정보를 출력한다.
-y, --assumeyesyum 진행중 나오는 질문을 모두 yes 로 처리한다. 삭제할 경우에는 의존성있는 모든 패키지까지 삭제되므로 주의해야 한다.


install

패키지를 설치한다. 의존성있는 패키지까지 같이 설치해 준다.

update 

yum update httpd 와 같이 패키지명이 주어질 경우 해당 패키지의 새 버전이 있으면 update 한다. 패키지명이 없을 경우 전체 시스템에서 update 될 패키지를 확인후 update 한다. -y 옵션을 줄 경우 묻지 않고 업데이트하므로 주의해야 한다.

전체 update 수행시 배포본의 minor 버전이 변경될 수 있다. Ex: RHEL 6.1 -> 6.4

check-update

update 될 패키지의 목록을 출력한다.

clean

The following are the ways which you can invoke yum in clean mode. Note that "all files" in the commands below means "all files in currently enabled repositories". If you want to also clean any (temporarily) disabled repositories you need to use --enablerepo=’*’ option.


check

check Checks the local rpmdb and produces information on any problems it finds. You can pass the check command the arguments "dependencies" or "duplicates", to limit the checking that is performed (the default is "all" which does both).

The info command can also take ranges of transaction ids, of the form start..end, which will then display a merged history as if all the transactions in the range had happened at once.

Eg. "history info 1..4" will merge the first four transactions and display them as a single transaction. help Produces help, either for all commands or if given a command name then the help for that particular command.


repolist

현재 등록된 repossitory list 를 출력한다. repository 설정은 /etc/yum.repos.d/ 에서 확인할 수 있다.

yum search string

패키지명 및 description 에 "string" 들어간 패키지들을 출력한다. 

provides

yum search path-string

패키지에 포함된 파일명이 string 과 일치하는 패키지들을 출력한다.  예로 다음 명령어는 httpd.conf 란 파일이 있는 모든 패키지를 출력한다.

yum provides '*/httpd.conf'
 
389-admin-1.1.29-1.el6.i686 : 389 Administration Server (admin)
Repo        : epel
Matched from:
Filename    : /etc/dirsrv/admin-serv/httpd.conf
piranha-0.8.6-2.el6_4.1.x86_64 : Cluster administation tools
Repo        : updates
Matched from:
Filename    : /etc/sysconfig/ha/conf/httpd.conf
BASH

위와 같이 /etc/dirsrv/admin-serv/에 있는 httpd.conf 도 출력이 된다. /etc/httpd/ 밑에 httpd.conf 가 있는 패키지만 출력하고 싶다면 다음과 같이 경로를 지정한다.

yum provides '/etc/http*/httpd.conf'
 
httpd-2.2.15-28.el6.centos.x86_64 : Apache HTTP Server
Repo        : updates
Matched from:
Filename    : /etc/httpd/conf/httpd.conf
BASH


localinstall

yum repository 를 제공하지 않고 rpm 으로만 제공하는 패키지가 있을 경우 (Ex: MySQL) 유용한 명령어다.

rpm 을 로컬에 다운로드하고 yum localinstall 로 설치하면 된다.

rpm -ivh 로 설치할 수도 있지만 yum  으로 작업하면 transaction 기록이 남으므로 yum history 를 사용하여 rollback 이 가능하다.

rpm 제작사의 서명이 없어서 에러가 날수 있으므로 --nogpgcheck 옵션을 추가해야 할 경우도 있다.

yum plugin

yum 은 plugin 으로 기능을 확장할 수 있다. 사용가능한 전체 플러그인 목록은 "yum search yum-plugin" 명령어로 볼수 있다.

yum 을 실행하면 다음과 같이 현재 기동된 plugin 목록을 표시한다.

Loaded plugins: fastestmirror, presto, refresh-packagekit
CODE


유용한 플러그인은 다음과 같다.

yum download only plugin

yum package 를 설치하지 않고 rpm 을 다운로드만 해주는 플러그인이다.

plugin 설치는 다음 yum 명령으로 설치하자.

yum install yum-downloadonly
BASH


download 시에는 --downloadonly 옵션을 붙여서 yum 을 실행하면 된다.


yum install postfix -y --downloadonly  
BASH

CentOS 7 에서는 yumdownloader 라는 별도의 명령어로 분리되었습니다

$ yumdownloader python --source
CODE


/var/cache/yum/ 에 다운로드 패키지 저장되니 아래처럼 하면 됨

yum install postfix -y --downloadonly --downloaddir=/opt
BASH
참고


verify plugin

설치된 패키지를 검증해 주는 플러그인이다.

다음 명령어로 httpd 패키지를 검증할 수 있다.

yum verify httpd
BASH


httpd 패키지의 설정파일의 수정 여부를 검증하려면 다음과 같이 수행한다.

yum verify --verify-filenames='/etc/httpd/*'  --verify-configuration-files=yes
BASH

특정 플러그인 disable

yum 실행시 --disableplugin 옵션으로 특정 플러그인의 사용을 잠시 중지할 수 있다. RHEL 의 경우 네트웍이 미구성되었거나 아직 subscription 을 등록 안 했을 경우 yum 실행시 RHN(RedHat Network) 에 연결하려고 하므로 DVD 나 ISO 로 local repository 를 만들어도 패키지를 설치할수 없다. 이럴 경우 다음과 같이 두 개의 plugin 을 잠시 중지시켜주면 RHN 연결과 상관없이 패키지를 설치할 수 있다.

yum --disableplugin=subscription-manager,rhnplugin install git -y
CODE


yum 설치 history 및 transaction 관리

패키지 설치, 변경, 삭제로 인해 내부 저장소가 변경되는 작업을 트랜잭션이라고 하며 RHEL6/CentOS 6 에 포함된 yum 부터는 트랜잭션 내역을 확인하고 rollback 을 할 수 있다. 

트랜잭션 목록 보기

yum history 를 옵션없이 실행하거나 옵션에 list 를 주면 최근 트랜잭션 목록을 볼 수 있다.

root@localhost:~:> yum history list
 

Loaded plugins: fastestmirror, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     8 | root <root>              | 2014-01-08 05:51 | Install        |    1   
     7 | root <root>              | 2014-01-08 04:23 | Reinstall      |    1   
     6 | root <root>              | 2014-01-08 03:18 | Reinstall      |    1   
     5 | root <root>              | 2014-01-07 06:44 | I, U           |    4   
     4 | root <root>              | 2014-01-02 05:32 | I, U           |    3   
     3 | root <root>              | 2014-01-01 03:48 | Install        |    4 EE
     2 | root <root>              | 2014-01-01 03:15 | I, U           |   28   
     1 | System <unset>           | 2013-12-15 03:43 | Install        |  534 
BASH


모든 트랜잭션을 보려면 list 옵션뒤에 all 뒤에 키워드를 주면 된다.

root@localhost:~:> yum history list all
BASH


특정 범위내 트랜잭션만 보려면 "시작 트랜잭션 번호".."종료 트랜잭션 번호" 형식으로 입력하면 된다. 다음은 트랜잭션 번호가 30 에서 35인 목록을 출력한다.

yum history list 30..35
Loaded plugins: fastestmirror, replace
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    35 | root <root>              | 2014-01-12 16:53 | I, U           |    3 EE
    34 | root <root>              | 2014-01-12 14:05 | Install        |    1   
    33 | root <root>              | 2014-01-12 14:05 | Erase          |    2   
    32 | root <root>              | 2014-01-12 13:00 | Install        |    2   
    31 | root <root>              | 2014-01-12 13:00 | Erase          |    1   
    30 | root <root>              | 2014-01-02 10:18 | Install        |    5   
history list
BASH


트랜잭션에서 정보 추출

마지막 트랜잭션 정보 보기

root@localhost:~:> yum history info

Loaded plugins: fastestmirror, security
Transaction ID : 8
Begin time     : Wed Jan  8 05:51:29 2014
Begin rpmdb    : 541:b7c34882afac2a58081bb274b5aaf30c2f993335
End time       :            05:51:31 2014 (2 seconds)
End rpmdb      : 542:4124c5c718def4131929c4ca08df78611232aa42
User           : root <root>
Return-Code    : Success
Command Line   : install mc
Transaction performed with:
    Installed     rpm-4.8.0-37.el6.x86_64                       @anaconda-CentOS-201311272149.x86_64/6.5
    Installed     yum-3.2.29-43.el6.centos.noarch               @updates
    Installed     yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201311272149.x86_64/6.5
Packages Altered:
    Install mc-1:4.7.0.2-3.el6.x86_64 @base
history info
BASH


ID 가 4 인 트랜잭션 정보 보기

root@localhost:~:> yum history info 4

Loaded plugins: fastestmirror, security
Transaction ID : 4
Begin time     : Thu Jan  2 05:32:21 2014
Begin rpmdb    : 539:85ca42f3d13cc18b6c4e179d32d564ba2ad47345
End time       :            05:32:30 2014 (9 seconds)
End rpmdb      : 540:a28a774308ff5f83227157e08f47bb2b3aa02618
User           : root <root>
Return-Code    : Success
Command Line   : localinstall git-1.8.3.1-1.sdl6.x86_64.rpm perl-Git-1.8.3.1-1.sdl6.noarch.rpm
Transaction performed with:
    Installed     rpm-4.8.0-37.el6.x86_64                       @anaconda-CentOS-201311272149.x86_64/6.5
    Installed     yum-3.2.29-43.el6.centos.noarch               @updates
    Installed     yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201311272149.x86_64/6.5
Packages Altered:
    Updated     git-1.7.1-3.el6_4.1.x86_64          @anaconda-CentOS-201311272149.x86_64/6.5
    Update          1.8.3.1-1.sdl6.x86_64           @/git-1.8.3.1-1.sdl6.x86_64
    Updated     perl-Git-1.7.1-3.el6_4.1.noarch     @anaconda-CentOS-201311272149.x86_64/6.5
    Update               1.8.3.1-1.sdl6.noarch      @/perl-Git-1.8.3.1-1.sdl6.noarch
    Dep-Install perl-TermReadKey-2.30-13.el6.x86_64 @base
history info
BASH


트랜잭션 되돌리기

yum history undo ID 명령어로 특정 트랜잭션을 되돌릴 수 있다. (ID는 트랜잭션 번호이다)

예로 다음과 같이 트랜잭션 8에서 mc 라는 패키지를 설치했을 경우

root@localhost:~:> yum history list

Loaded plugins: fastestmirror, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     8 | root <root>              | 2014-01-08 05:51 | Install        |    1   
     7 | root <root>              | 2014-01-08 04:23 | Reinstall      |    1   
     6 | root <root>              | 2014-01-08 03:18 | Reinstall      |    1   
     5 | root <root>              | 2014-01-07 06:44 | I, U           |    4   
     4 | root <root>              | 2014-01-02 05:32 | I, U           |    3   
     3 | root <root>              | 2014-01-01 03:48 | Install        |    4 EE
     2 | root <root>              | 2014-01-01 03:15 | I, U           |   28   
     1 | System <unset>           | 2013-12-15 03:43 | Install        |  534   
history list
BASH

yum history undo 8 을 실행하면 8번 트랜잭션에 대해 undo 를 수행한다. undo 의 결과는 해당 트랜잭션이 무엇이었는지에 따라 다르다. 설치였으면 undo 는 삭제가 되고 삭제였다면 undo 는 설치가 된다.

예로 트랜잭션 8번에서 mc 라는 패키지를 설치했으면 undo 8의 결과는 mc 패키지의 삭제가 된다

transaction 8 번 되돌리기

root@localhost:~:>  yum history undo 8

Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: data.nicehosting.co.kr
 * extras: data.nicehosting.co.kr
 * updates: data.nicehosting.co.kr
Undoing transaction 8, from Wed Jan  8 05:51:29 2014
    Install mc-1:4.7.0.2-3.el6.x86_64 @base
Resolving Dependencies
--> Running transaction check
---> Package mc.x86_64 1:4.7.0.2-3.el6 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================
 Package              Arch                     Version                             Repository               Size
=================================================================================================================
Removing:
 mc                   x86_64                   1:4.7.0.2-3.el6                     @base                   5.4 M
Transaction Summary
=================================================================================================================
Remove        1 Package(s)
Installed size: 5.4 M
Is this ok [y/N]: y
BASH


undo의 결과로 다음과 같이 transaction 9번이 생겼고 Action 은 Erase 가 된다.

root@localhost:~:> yum history list  

Loaded plugins: fastestmirror, security
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     9 | root <root>              | 2014-01-08 05:58 | Erase          |    1   
     8 | root <root>              | 2014-01-08 05:51 | Install        |    1   
     7 | root <root>              | 2014-01-08 04:23 | Reinstall      |    1   
     6 | root <root>              | 2014-01-08 03:18 | Reinstall      |    1   
     5 | root <root>              | 2014-01-07 06:44 | I, U           |    4   
     4 | root <root>              | 2014-01-02 05:32 | I, U           |    3   
     3 | root <root>              | 2014-01-01 03:48 | Install        |    4 EE
     2 | root <root>              | 2014-01-01 03:15 | I, U           |   28   
     1 | System <unset>           | 2013-12-15 03:43 | Install        |  534   
history list
BASH


모든 history 를 삭제하는 위험한 명령어이다. 특별한 이유가 없다면 실행하지 않는다.

yum history new
CODE


같이 보기

참고