Advanced Package Tool
apt-get(Advanced Packaging Tool)은 우분투(Ubuntu)를 포함안 데비안(Debian)계열의 리눅스에서 쓰이는 패키지 관리 명령어 도구이다. 우분투에는 GUI로 되어 있는시냅틱 꾸러미 관리자도 있기는 하지만 이런 저런 개발관련 패키지를 설치할 때는 커맨드기반인 apt-get이 더 편하기도 하다.
Categories
- add-apt-repository
- apt-get
- apt-key
- apt-cache - Query the APT cache
- apt.conf - Configuration file for APT
- apt-offline
- dpkg
apt-get
SourcesList
As part of its operation, Apt uses a file that lists the 'sources' from which packages can be obtained. This file is /etc/apt/sources.list
.
The entries in this file normally follow this format (the entries below are fictitious and should not be used):
deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3
- Archive type
- The first word on each line, deb or deb-src, indicates the type of archive. Deb indicates that the archive contains binary packages (deb), the pre-compiled packages that we normally use. Deb-src indicates source packages, which are the original program sources plus the Debian control file (.dsc) and the diff.gz containing the changes needed for packaging the program.
- Repository URL
- The next entry on the line is a URL to the repository that you want to download the packages from. The main list of Debian repository mirrors is located here.
- Distribution
- The 'distribution' can be either the release code name / alias (jessie, stretch, buster, sid) or the release class (oldstable, stable, testing, unstable) respectively. If you mean to be tracking a release class then use the class name, if you want to track a Debian point release, use the code name.
- For example, if you have a system running Debian 9.5 "stretch" and don't want to upgrade when Debian buster releases, use 'stretch' instead of 'stable' for the distribution. If you always want to help test the testing release, use 'testing'. If you are tracking buster and want to stay with it from testing to end of life, use 'buster'.
- Component
- 패키지 저장소 내의 특정 카테고리를 정의합니다. 일반적으로 main, restricted, universe, multiverse 등이 있습니다. 각 컴포넌트는 특정 범주의 패키지 집합을 나타냅니다.
- main - consists of DFSG-compliant packages, which do not rely on software outside this area to operate. These are the only packages considered part of the Debian distribution.
- contrib - packages contain DFSG-compliant software, but have dependencies not in main (possibly packaged for Debian in non-free).
- non-free - contains software that does not comply with the DFSG.
- restricted - 제한적 지원이 있는 패키지.
- universe - 커뮤니티가 유지 관리하는 패키지.
- multiverse - 자유롭지 않은 라이선스를 가진 패키지.
Configuration
설정파일 목록은 /etc/apt/apt.conf.d/
디렉토리에 존재한다.
HTTPS 인증 SKIP
Acquire::[URL]::Verify-Peer
속성을 false
로 변경하면 된다. 중간의 [URL]
에 해당 HOST 이름을 입력하면 된다.
만약 HOST명이 nexus.my.local
이라 가정할 때, 아래와 같이 적용할 수 있다.
설정파일에 추가하고 싶다면 아래와 같이 적용하면 된다.
$ echo "Acquire::https::nexus.my.local::Verify-Peer \"false\";" | sudo tee /etc/apt/apt.conf.d/nexus-my-local-conf
Timeout
/etc/apt/apt.conf.d/99timeout
파일에 다음 내용을 추가하였다.
non-interactive mode
비 대화식 모드로 패키지를 설치하고 싶다면 아래와 같이 환경변수를 설정하면 된다.
Personal Package Archive (PPA)
항목 참조.
OS 최신버전 업그레이드
do-release-upgrade 를 사용하자.
자동 업데이트 Enable
unattended-upgrades 는 Ubuntu system 의 최신 보안 패치 및 기타 업데이트를 자동으로 수행하고 시스템을 유지, 관리 하는 것에 목적이 있는 서비스 입니다.
Ubuntu 를 설치하면 기본적으로 해당 서비스는 설치되어 작동하고 있습니다. 만약 설치가 안되어 있다면 아래와 같이 설치를 진행합니다.
관련 설정은 /etc/apt/apt.conf.d/50unattended-upgrades
파일 확인. 자세한 내용은 unattended-upgrades 항목 참조.
자동 업데이트 Disable
- UnattendedUpgrades - Debian Wiki
- 6.8. Keeping a System Up to Date
- (Ubuntu20) Unattended upgrade 비활성화
Ubuntu 최초 설치 직후 /etc/apt/apt.conf.d/20auto-upgrades
파일에 다음과 같이 설정되어 있을 수 있다:
각 필드는 다음과 같다:
-
APT::Periodic
::Update-Package-Lists
- 패키지 목록을 정기적으로(1일에 한 번) 새로 고친다.
apt update
와 같음.-
0
- 자동 업데이트가 비활성화됨을 의미합니다. -
1
- 시스템이 주기적으로 업데이트를 확인하고 적용합니다.
-
-
APT::Periodic
::Unattended-Upgrade
- 이 옵션이 활성화 되면 일일 간격으로 unattended-upgrade 패키지지가 자동으로 업그레이드 한다.
- 기본 값으로 보안 업데이트만 처리한다.
/etc/apt/apt.conf.d/50unattended-upgrades
파일에서 커스터마이징 가능하다. - 이 옵션은
dpkg-reconfigure -plow unattended-upgrades
명령을 실행하여 debconf의 도움으로 설정 가능하다. - 만약 apt-listbugs 가 설치되었다면 심각한 버그의 영향을 받는 패키지의 자동 업그레이드를 방지한다.
-
0
- 자동 업데이트가 비활성화됨을 의미합니다. -
1
- 시스템이 주기적으로 업데이트를 확인하고 적용합니다.
-
-
APT::Periodic
::Download-Upgradeable-Packages
- 패키지 목록을 정기적으로(1일에 한 번) 실제 패키지를 다운로드합니다.
-
APT::Periodic
::AutocleanInterval
- 더 이상 사용되지 않는 패키지(배포에서 더 이상 참조하지 않는 패키지)가 APT 캐시에서 제거되는 빈도를 제어합니다. 이렇게 하면 APT 캐시가 적당한 크기로 유지되므로 해당 작업에 대해 걱정할 필요가 없습니다.
우분투 Pro 광고를 제거하는 방법
업데이트를 모두 마치고 나서도 다음과 같이 광고 문구가 출력된다:
Try Ubuntu Pro beta with a free personal subscription on up to 5 machines.
Learn more at https://ubuntu.com/pro
제거하고 싶다면 Ubuntu#우분투 Pro 광고를 제거하는 방법 항목 참조.
Offline 설치 방법
이 방법을 사용하려면 해당 패키지가 설치되지 않은 상태여야 한다.
따라서 아무것도 설치되지 않는 우선 격리된 컨테이너 사용을 추천하며, 원하는 OS 버전 선택을 위해 docker를 사용한다.
예를 들어 ubuntu의 20.04
버전, openssh-server를 설치하고 싶다면:
apt를 사용하여 원하는 패키지 다운로드:
참고로 캐시 폴더 기본 경로는 /var/cache/apt/archives
이다.
USB 등을 이용하여 *.deb
파일을 복사한다.
dpkg를 사용하여 설치한다:
apt-offline
apt-offline 패키지를 사용한 방법도 있다.
직접 다운로드 및 설치 방법
종속성 목록을 확인하자.
현재 디렉토리에 다운로드 받자.
재귀적으로 종속성 확인 -> 다운로드 반복 이후, dpkg 로 설치.
패키지 잠금
apt-mark 를 사용하면 된다.
예를 들어 설치, 업그레이드 또는 제거에 사용할 수 없는 apache2 패키지를 만들려면 터미널에서 루트 권한으로 다음 명령을 사용할 수 있습니다.
이 패키지를 다시 업데이트할 수 있도록 하려면 'hold'를 'unhold'로 바꾸세요.
설치중 실패 이후 조치 방법
이 명령어를 실행하면 dpkg는 설정이 완료되지 않은 패키지들을 찾아내어 그 설정 과정을 다시 시도합니다. 이를 통해 시스템의 패키지 상태를 정상화할 수 있습니다.
또는 apt --fix-broken install
가 있다. 이건 필요하다면 apt 에서 알려준다:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
cuda-toolkit-12-4 : Depends: cuda-compiler-12-4 (>= 12.4.1) but it is not going to be installed
Depends: cuda-libraries-12-4 (>= 12.4.1) but it is not going to be installed
Depends: cuda-libraries-dev-12-4 (>= 12.4.1) but it is not going to be installed
Depends: cuda-tools-12-4 (>= 12.4.1) but it is not going to be installed
Depends: cuda-documentation-12-4 (>= 12.4.127) but it is not going to be installed
Depends: cuda-nvml-dev-12-4 (>= 12.4.127) but it is not going to be installed
nvidia-driver-560-open : Depends: nvidia-compute-utils-560 (= 560.35.03-0ubuntu1) but it is not going to be installed
Depends: nvidia-utils-560 (= 560.35.03-0ubuntu1) but it is not going to be installed
Recommends: libnvidia-compute-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-decode-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-encode-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-fbc1-560:i386 (= 560.35.03-0ubuntu1)
Recommends: libnvidia-gl-560:i386 (= 560.35.03-0ubuntu1)
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Accept an invalid certificate (SSL 인증서 확인 스킵 방법)
// Do not verify peer certificate
Acquire::https::Verify-Peer "false";
// Do not verify that certificate name matches server name
Acquire::https::Verify-Host "false";
or just for a specific host:
Acquire::https::repo.domain.tld::Verify-Peer "false";
Acquire::https::repo.domain.tld::Verify-Host "false";
명령행에 임시로 적용:
apt -o "Acquire::https::Verify-Peer=false" update
apt -o "Acquire::https::Verify-Peer=false" install curl
프록시 서버 설정
프록시 서버 쓰면 인증서 검사 삑날수 있으니 다음과 같이 사용하자:
sudo apt -o Acquire::http::proxy=http://127.0.0.1:8080/ -o Acquire::https::proxy=http://127.0.0.1:8080/ -o Acquire::https::Verify-Peer=false ...
Example
-
sudo apt-get update
:패키지 인덱스 인덱스 정보를 업데이트.apt-get
은 인덱스를 가지고 있는데 이 인덱스는/etc/apt/sources.list
에 있다. 이곳에 저장된 저장소에서 사용할 패키지의 정보를 얻는다. -
sudo apt-get upgrade
: 설치되어 있는 패키지를 모두 새버전으로 업그레이드 한다. -
sudo apt-get dist-upgrade
: 의존성검사하며 설치하기. -
sudo apt-cache search [PKG_NAME]
: 패키지 검색 (와일드카드 '*'가 적용된다) -
sudo apt-cache show [PKG_NAME]
: 패키지 정보 보기 (버전 목록이 모두 출력된다) -
sudo apt-get purge [PKG_NAME]
: 패키지 제거시 관련 설정파일도 함께 제거. -
sudo apt-get autoremove
: 자동으로 사용하지 않는 패키지를 제거한다. -
sudo add-apt-repository [PPA_NAME]
: 저장소 추가. -
sudo add-apt-repository --remove [PPA_NAME]
: 저장소 제거. -
sudo apt-cache policy [PKG_NAME]
: 패키지 버전 보기 -
sudo apt-get install [PKG_NAME]=[PKG_VERSION]
: 패키지 특정버전 다운로드. (버전명이8.11.7-ce.0
와 같은 식으로 길 경우8.11.7*
와 같이 축약 가능) -
apt-get install --only-upgrade [PKG_NAME]
: 해당 패키지만 업데이트. -
apt list --installed
: 설치된 패키지 목록을 볼 수 있다.dpkg -l
도 가능. -
apt list --upgradable
: 업그레이드 가능한 패키지 목록을 볼 수 있다. -
apt-cache depends [PKG_NAME]
: 패키지의 종속성 목록을 볼 수 있다. -
apt-cache rdepends [PKG_NAME]
: 패키지의 역 종속성 목록을 볼 수 있다.
Troubleshooting
Server certificate verification failed (SSL 인증서 확인 실패)
apt.conf
파일에 아래와 같이 설정하면 된다.
중요한 점은 해당하는 HOST명을 속성 중간에 입력해야 한다. 따라서 문법은 아래와 같다. (아래의 {HOST_NAME}
부분에 입력하면 된다)
명령행으로 실행하고 싶을 경우 아래와 같이 -o
파라미터를 사용하면 된다.
GPG 에러 무시
-
--allow-unauthenticated
- Ignore if packages can't be authenticated and don't prompt about it. This is useful for tools like pbuilder. Configuration
Item:
APT::Get
::AllowUnauthenticated
You can make this setting permanent by using your own config file at /etc/apt/apt.conf.d/
dir.
ADD PPA repo
PPA를 사용할 경우 아래와 같이 add-apt-repository명령을 사용하면 된다.
Unable to fetch some archives
아래와 같은 에러가 발생할 수 있다.
원문은 아래와 같다.
아래와 같은 방법이 있다.
-
apt-get update
다시 해본다. -
apt-get install --fix-missing
옵션을 사용. - DNS서버를 다시 설정.
/etc/resolv.conf
만약 Docker에서 발생된 문제라면 Docker의 Daemon configuration file (/etc/docker/daemon.json
)1에 dns를 아래와 같이 추가하는게 좋다.
Invalid ELF header
프로그램 실행시 정상적으로 실행되지 않고 특정 라이브러리가 아래와 같은에러가 날 수 있다.
$ simplescreenrecorder
simplescreenrecorder: error while loading shared libraries: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: invalid ELF header
dpkg를 사용하여 해당 라이브러리의 패키지명을 확인한다.
$ dpkg -S /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
libqt5core5a:amd64: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
그리고 해당 패키지를 다시 설치한다.
The following packages have been kept back
패키지 종속성이 변경될 경우 출력된다. 다음 명령으로 강제로 새로운 패키지 업데이트 가능하다:
Please install all available updates for your release before upgrading.
업데이트 위해 do-release-upgrade
명령 시 다음과 같은 에러 발생:
Checking for a new Ubuntu release
Please install all available updates for your release before upgrading.
apt 업데이트를 전부 완료하면 된다.
라이브러리를 찾을 수 없지만 패키지로는 설치되어 있다고 출력될 때
ldd 같은 명령으로 라이브러리를 확인해보면 찾을 수 없을 때가 있다:
ldd /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstopenmpt.so
...
libmpg123.so.0 => not found
libvorbis.so.0 => /lib/x8
dpkg -L libmpg123-0
명령으로 패키지 관련파일을 조회해보자:
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libmpg123.so.0.46.7
/usr/share
/usr/share/doc
/usr/share/doc/libmpg123-0
/usr/share/doc/libmpg123-0/changelog.Debian.gz
/usr/share/doc/libmpg123-0/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/libmpg123-0
/usr/lib/x86_64-linux-gnu/libmpg123.so.0
lib 파일이 있어서 cat /usr/lib/x86_64-linux-gnu/libmpg123.so.0
으로 조회해 보면 파일이 없다고 출력될 때가 있다. 이럴 경우에 해당 라이브러리를 다시 설치하자. apt-get install --reinstall ...
명령을 사용하면 된다:
See also
- dpkg
- snapcraft (snap)
- aptitude
- Personal Package Archive (PPA)
- GPG
- reprepro
- SonatypeNexus:Apt: Sonatype Nexus의 apt Repository 설정 방법.
- Package management system
- aptly
- Pulp
Favorite site
- Wikipedia (en) APT
- How can PPAs be removed?
- What is the correct way to completely remove an application?
- HOWTO: GPG sign and verify deb packages and APT repositories 2 (GPG, APT)
References
-
자세한 내용은 Docker:Config를 참조 ↩
-
HOWTO_-GPG_sign_and_verify_deb_packages_and_APT_repositories-_Packagecloud_Blog.pdf ↩