====== Linux apt (Advanced Packaging Tool) 및 Debian 계열 패키지 관리 ======
* Debian 계열 패키지 package 관리 프로그램.
* apt는 [[linux:yum|Linux yum]]과 같은 역할이고, dpkg는 rpm과 같은 역할
* [[linux:ubuntu:package_management|Ubuntu 패키지 관리]]
* [[linux:apt_offline|apt-offline]]
* [[linux:deb_get|deb-get]]
* [[linux:aptitude|aptitude]]
* [[linux:nala|nala]]
* [[linux:debian:makedeb_mpm|makedeb / mpm]]
===== 설치 =====
sudo apt install
sudo apt install =
# apt-mark hold 로 버전 고정
===== 검색 =====
apt-cache search keyword
===== apt-file / package 소유 파일 목록 =====
* 어떤 파일이 어느 패키지에 들어있는지 여부를 찾아주는 툴
* ''apt-file search 파일명''
* 이 전에 먼저 ''sudo apt-file update'' 로 데이베이스 생성해둬야함.
sudo apt-file update
apt-file list
* [[linux:dpkg|dpkg]] 명령으로 보기
dpkg -L
# *.deb 파일의 컨텐츠 보여주기
dpkg -c
===== cache clean =====
# 캐시 삭제
sudo apt clean --dry-run # 일단 확인만
sudo apt clean
# 새 버전이 존재하는 패키지는 cache에서 지운다.
sudo apt autoclean --dry-run # 일단 확인만
sudo apt autoclean
===== fix-broken =====
* ''dpkg'' 등으로 설치를 했는데, 그에 대한 의존성은 설치가 덜 됐을 때 덜 설치된 의존성을 보정해준다.
sudo apt-get --fix-broken install
===== 특정 패키지의 의존성 목록 =====
* ''apt-cache showpkg [package-name]'' : 해당 패키지가 의존하는 패키지 목록
* ''dpkg -I package.deb''
===== 특정 패키지의 저장소 정보 =====
* 존재하는 모든 버전과 해당 저장소 목록을 볼 수 있다.
apt-cache policy [package-name]
===== 설치된 패키지 목록 =====
apt list --installed
===== Upgrade 가능 목록 =====
apt list --upgradable
===== unauthorized =====
sudo apt-get update --allow-unauthenticated
===== apt-mark =====
* 특정 버전으로 고정. 업그레이드를 망지한다.
# 현재 설치 버전으로 고정
sudo apt-mark hold jenkins
# 고정 풀기
sudo apt-mark unhold jenkins
# 고정 목록
sudo apt-mark showhold
* 기타 방법 - [[https://askubuntu.com/questions/18654/how-to-prevent-updating-of-a-specific-package|updates - How to prevent updating of a specific package? - Ask Ubuntu]]
* ''synaptic''에서 **Package -> Lock Version** 메뉴로도 가능.
# dpkg
echo " hold" | sudo dpkg --set-selections # hold
echo " install" | sudo dpkg --set-selections # unhold
dpkg --get-selections # 상태 조회
dpkg --get-selections # 특정 패키지 상태조회
dpkg --get-selections | grep "\
sudo aptitude unhold
===== Aptik =====
* http://www.teejeetech.in/2014/09/aptik-v16.html
===== Pinning =====
* [[https://help.ubuntu.com/community/PinningHowto|Pinning HowTo]]
===== apt-key =====
man apt-key 8
* ''apt-key'' 명령은 **deprecated** 되었으며 [[linux:ubuntu:25.04|Ubuntu 25.04]]에서는 아예 삭제되었다. 아래와 같은 명령을 사용한다면 후자로 변경해줘야 한다.
* [[devops:ansible|Ansible]] 에서 ''apt-key''도 사용하지 말 것.
==== script의 경우 ====
# 사용 금지
wget -qO- https://myrepo.example/myrepo.asc | sudo apt-key add -
# 이렇게 사용.
wget -qO- https://myrepo.example/myrepo.asc | sudo tee /etc/apt/trusted.gpg.d/myrepo.asc
* 명시적 ''signed-by'' 키의 경우 **''/etc/apt/keyrings/''** 아래에 저장하고 repository source 파일에 ''deb [signed-by=/usr/share/keyrings/filename.gpg] ...'' 처럼 지정해준다.
* ASCII armored 파일의 경우 파일 확장자가 **''.asc''** 여야 한다.
* Open PGP 바이너리의 경우(''%%gpg --dearmor%%'' 로 저장했거나) **''.gpg''** 확장자로 저장해야 한다.
==== ansible 의 경우 ====
* [[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/deb822_repository_module.html|ansible.builtin.deb822_repository module – Add and remove deb822 formatted repositories — Ansible Community Documentation]]
* Repository 추가와 key 추가를 함께 동시에 한다.
* [[https://gist.github.com/roib20/27fde10af195cee1c1f8ac5f68be7e9b|Example usages of the new `deb822_repository` Ansible module · GitHub]]
- name: Add repo using key from URL
deb822_repository:
name: example
types: deb
uris: https://download.example.com/linux/ubuntu
suites: '{{ ansible_distribution_release }}'
components: stable
architectures: amd64
signed_by: https://download.example.com/linux/ubuntu/gpg
* https://gist.github.com/roib20/27fde10af195cee1c1f8ac5f68be7e9b : 각종 deb 패키지 리포지토리 예시
===== CheatSheet =====
* [[http://www.cyberciti.biz/tips/linux-debian-package-management-cheat-sheet.html|Debian Linux apt-get package management cheat sheet]]
* [[http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/|25 Useful Basic Commands of APT-GET and APT-CACHE for Package Management]]
* [[http://www.tecmint.com/apt-advanced-package-command-examples-in-ubuntu/|15 Examples of How to Use New Advanced Package Tool (APT) in Ubuntu/Debian]]
===== Repository =====
* [[http://www.hackgnar.com/2016/01/creating-remote-apt-package.html|hackgnar: Creating Remote APT Package Repositories on Github]]
* [[https://pmateusz.github.io/linux/2017/06/30/linux-secure-apt-repository.html|Personal DEB Package Repository using GitHub Pages | Building Pyramids]]
===== 가장 빠른 미러 찾기 =====
* [[https://linuxconfig.org/how-to-select-the-fastest-apt-mirror-on-ubuntu-linux|How to select the fastest apt mirror on Ubuntu Linux - Linux Tutorials - Learn Linux Configuration]]
===== 다음 패키지를 과거 버전으로 유지합니다: =====
* ''The following packages have been kept back:''
* 설치돼 있는 패키지의 의존성에 어떤 변경이 발생해서 제대로 변경된 의존성을 설치하고 다른 것은 제거 하는 등의 작업이 일어날 때 발생하는 오류.
* [[https://askubuntu.com/|apt - "The following packages have been kept back:" Why and how do I solve it? - Ask Ubuntu]]
==== 신규 패키지와 함께 업그레이드 ====
* 신규 설치 패키지를 보여주며 업그레이드한다. 그런데 지워야 할 패키지가 있을 경우에는 작동하지 않는 듯 하다.
sudo apt-get --with-new-pkgs upgrade
==== 명시적 install ====
* upgrade 가 안되는 패키지를 명확하게 다시 ''apt install '' 로 설치명령을 내리면 어떤 패키지의존성이 변경되었고 무엇을 더 설치하고 무엇을 지우는지 등이 나온다. 이를 확인하고서 설치 여부를 결정하면 된다.
sudo apt install package1 package2 ...
다음의 추가 패키지가 설치될 것입니다 :
<어쩌구 저쩌구>
다음 패키지를 지울 것입니다:
<어쩌구 저쩌구>
계속 하시겠습니까? [Y/n] <-- 선택하면 됨.
==== 강제 업그레이드 ====
* 신규 의존성을 모두 강제로 업그레이드한다.
* 다소 위험할 수도 있다.
sudo apt dist-upgrade
===== 참조 =====
* [[https://wnw1005.tistory.com/359|씨실과 날실 - IT :: 데비안(Debian), 우분투(Ubuntu)의 APT 계열 명령 연재 목록]]
* [[https://askubuntu.com/questions/1093451/how-to-switch-apt-mirror-from-the-commandline|command line - How to switch APT mirror from the commandline? - Ask Ubuntu]]
* https://wiki.debian.org/PackageManagement
* [[https://www.ubuntupit.com/how-to-remove-broken-packages-in-ubuntu-linux/|How to Remove Broken Packages in Ubuntu Linux]]