본문 바로가기
공부정리

Ubuntu apt로 패키지 설치 중 발생한 에러 추적기

by 에드박 2021. 9. 22.

Ubuntu에서는 apt(Advanced Packaging Tool)로 소프트웨어를 설치하거나 제거할 수 있습니다.

얼마전 놀토에서 Ubuntu서버에 도커 컨테이너가 아닌 호스트에 직접 mysql을 설치해야 했습니다.

(궁금하신 분은 이 글을 참고해주세요!)

 

Ubuntu 18.04버전을 기준으로 설명합니다.

 

에러가 났던 상황을 간단하게 설명하면 다음과 같습니다.

  • Ubuntu의 기본 저장소(Repository)는 MariaDB 패키지가 있지만 버전이 오래됐습니다. (10.1x 버전이 존재)
  • 도커 컨테이너에 설치된 MariaDB 버전은 10.5x 버전이라서 dump 파일을 10.1x 버전에서는 읽을 수 없습니다.
  • Ubuntu 에 MariaDB에서 제공하는 저장소를 추가합니다.
  • 추가하는 명령어가 focal(Ubuntu 20.04 버전의 코드네임)으로 된것을 보고 추가진행 중인것을 중단했습니다.(control  + c, 강제종료)
  • 저장소 추가 명령어에 bionic으로 다시 추가했습니다.
  • MariaDB 10.5 설치 명령어가 오류가 나면서 설치되지 않습니다.
ubuntu@ip-172-31-1-88:~$ sudo apt install mariadb-server-10.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:

The following packages have unmet dependencies:
mariadb-server : Depends: mariadb-server-10.5 (>= 1:10.5.12+maria~focal) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

mariadb-server-10.5 패키지를 설치하려고 했으나 패키지가 손상됐다고 나오네요.

 

오랜 시간 추적끝에 저장소를 추가하던 도중 멈춰서 문제가 발생했다는걸 알았습니다.

저장소의 리스트가 있는 파일은 다음의 경로에 있습니다.

/etc/apt/sources.list

 

sources.list 파일을 열어보면 아래와 같이 다양한 저장소들이 있고 위에서 추가한 저장소들도 있음을 확인할 수 있습니다.

 

deb http://security.ubuntu.com/ubuntu bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse deb [arch=arm64,amd64,ppc64el]
http://mirror.lstn.net/mariadb/repo/10.5/ubuntu focal main # deb-src [arch=arm64,amd64,ppc64el]
http://mirror.lstn.net/mariadb/repo/10.5/ubuntu focal main deb [arch=ppc64el,arm64,amd64]
http://mirror.lstn.net/mariadb/repo/10.5/ubuntu bionic main # deb-src [arch=ppc64el,arm64,amd64]
http://mirror.lstn.net/mariadb/repo/10.5/ubuntu bionic main

여기서는 두가지 선택이 있습니다.

  1. 오류가 났던 저장소를 삭제한다.
  2. sources.list 파일 자체가 너무 많이 망가져서 어디를 건드려야할지 모르겠다. -> sources.list 파일을 초기화합니다.

1번 방법은 오류가 났던 저장소를 삭제한다는 말 그대로 파일 에디터로 열어서 해당 부분을 삭제하시면 됩니다.

2. sources.list 파일을 처음 상태로 초기화하기

약간 위험한 방법일 수 있어서 1번의 방법이 가능하다면 1번으로 진행해주세요.

 

1. 혹시 모르니 sources.list 파일을 백업합니다.

sudo cp /etc/apt/sources.list /etc/apt/sources.list.back

2. sources.list의 내용을 전부 삭제합니다.

3. https://repogen.simplylinux.ch/ 에 접속합니다.

4. Select your country탭에서 South korea를 선택합니다.

5. Select your release에서 Bionic 18.04 를 선택합니다. (자신에게 맞는 버전을 선택합니다. 사이트는 18.04까지만 지원합니다)

6. Ubuntu Branches탭에서 체크 박스를 전부 체크해주세요

7. Ubuntu Updates탭에서 Proposed 를 제외하고 전체를 선택해주세요.

8. (Optional) 3rd Parties Repos 탭에서는 필요한 서드파티 저장소를 선택합니다.

9. 페이지 가장 하단으로 가면 있는 Generate List 버튼을 클릭합니다.

10. 새로 나오는 페이지에서 Sources List 의 내용을 전부 복사해서 sources.list에 붙여넣습니다.

여기까지 하셨다면 sources.list 파일이 초기화 됐습니다!

댓글