본문 바로가기

리눅스

CentOS 7에서 yum 저장소(repository)를 변경하는 방법

728x90

CentOS 7에서 yum 저장소(repository)를 변경하는 방법

테스트 환경

  • 운영체제 버전 정보
$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

 

1. 기존 저장소 확인

현재 활성화된 저장소 목록과 상태를 확인할 수 있습니다.

yum repolist

 

2. 원하는 저장소 찾기

변경하려는 새로운 저장소를 찾아야 합니다. CentOS 기본 저장소 이외의 저장소를 사용하려면 해당 저장소의 URL을 알아야 합니다.

 

3. 기존 저장소 비활성화

저장소를 변경하려면 먼저 현재 사용 중인 저장소를 비활성화해야 합니다. 저장소의 설정 파일을 편집하여 enabled=0으로 설정하면 됩니다.

예를 들어, /etc/yum.repos.d/CentOS-Base.repo 파일을 편집하여 CentOS 기본 저장소를 비활성화할 수 있습니다.

sudo vim /etc/yum.repos.d/CentOS-Base.repo

파일 내에서 [base] 및 [updates] 섹션을 찾아 enabled=0으로 설정합니다.

 

4. 새로운 저장소 추가

새로운 저장소를 추가하려면 해당 저장소의 설정 파일을 /etc/yum.repos.d/ 디렉토리에 만들어야 합니다. 설정 파일은 .repo 확장자를 가지며 저장소 정보를 정의합니다.

예를 들어, /etc/yum.repos.d/mycustom.repo 파일을 생성하고 다음과 같이 내용을 추가할 수 있습니다.

sudo vim /etc/yum.repos.d/mycustom.repo
[mycustom]
name=My Custom Repository
baseurl=http://example.com/mycustom-repo
enabled=1
gpgcheck=0
  • name : 저장소 이름
  • baseurl : 저장소의 URL
  • enabled : 저장소를 활성화할지 여부 (1은 활성화, 0은 비활성화)
  • gpgcheck : GPG 체크를 수행할지 여부 (1은 수행, 0은 미수행)

5. 새로운 저장소 활성화

저장소 설정 파일을 추가한 후, 해당 저장소를 활성화합니다.

 

6. 캐시 업데이트

저장소 변경 사항을 적용하기 위해 yum 캐시를 업데이트합니다.

sudo yum clean all

이제 변경된 저장소에서 패키지를 설치하거나 업데이트할 수 있습니다.

 

새로운 저장소를 추가하고 이전 저장소를 비활성화하는 것은 주의해서 수행해야 합니다. 잘못된 저장소 설정은 시스템 패키지 관리에 문제를 일으킬 수 있으므로 신중하게 처리해야 합니다.

728x90
  • CentOS-Base.repo 파일 확인
cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

sed 명령어로 yum repository url 변경하기(mirror.kakao.com)

sed -i 's/^mirrorlist=http:\/\/mirrorlist.centos.org/#mirrorlist=http:\/\/mirrorlist.centos.org/g' CentOS-Base.repo
sed -i 's/^#baseurl=http:\/\/mirror.centos.org/baseurl=https:\/\/mirror.kakao.com/g' CentOS-Base.repo
  • CentOS-Base.repo 파일 확인
cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirror.kakao.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirror.kakao.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirror.kakao.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirror.kakao.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

 

728x90