Apt tips and tricks: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
(Added Knowledge Graph section)
(Fix: remove --- horizontal lines (12 removed))
 
Line 18: Line 18:
* 언제 사용하는가? Ubuntu/Debian 시스템 관리, 패키지 문제 해결, 오프라인 환경 설치
* 언제 사용하는가? Ubuntu/Debian 시스템 관리, 패키지 문제 해결, 오프라인 환경 설치


---


== Purpose ==
== Purpose ==
Line 28: Line 27:
* Non-goals: YUM/DNF(RHEL/CentOS) 패키지 관리, 소스 코드 컴파일
* Non-goals: YUM/DNF(RHEL/CentOS) 패키지 관리, 소스 코드 컴파일


---


== Key Concepts ==
== Key Concepts ==
Line 58: Line 56:
|}
|}


---


== Architecture ==
== Architecture ==
Line 76: Line 73:
</syntaxhighlight>
</syntaxhighlight>


---


== Workflow ==
== Workflow ==
Line 106: Line 102:
|}
|}


---


== Detailed Explanation ==
== Detailed Explanation ==
Line 173: Line 168:
dpkg는 많은 옵션을 제공하며, [https://www.cyberithub.com/21-practical-dpkg-command-examples-for-linux-beginners/#Example_13_How_to_Verify_all_the_Installed_Packages 이 페이지]에서 가장 실용적인 dpkg 명령어를 확인할 수 있습니다.
dpkg는 많은 옵션을 제공하며, [https://www.cyberithub.com/21-practical-dpkg-command-examples-for-linux-beginners/#Example_13_How_to_Verify_all_the_Installed_Packages 이 페이지]에서 가장 실용적인 dpkg 명령어를 확인할 수 있습니다.


---


== Configuration ==
== Configuration ==
Line 185: Line 179:
</syntaxhighlight>
</syntaxhighlight>


---


== Examples ==
== Examples ==
Line 229: Line 222:
</syntaxhighlight>
</syntaxhighlight>


---


== Best Practices ==
== Best Practices ==
Line 239: Line 231:
* dpkg --verify로 설치된 패키지 무결성 확인
* dpkg --verify로 설치된 패키지 무결성 확인


---


== Limitations ==
== Limitations ==
Line 248: Line 239:
* 오래된 커널 제거 시 현재 커널이 삭제 목록에 없는지 반드시 확인 필요
* 오래된 커널 제거 시 현재 커널이 삭제 목록에 없는지 반드시 확인 필요


---


== References ==
== References ==
Line 257: Line 247:
* https://www.cyberithub.com/21-practical-dpkg-command-examples-for-linux-beginners/
* https://www.cyberithub.com/21-practical-dpkg-command-examples-for-linux-beginners/


---


== Related Pages ==
== Related Pages ==
Line 268: Line 257:
* [[Kernel Management]]
* [[Kernel Management]]


---


[[Category:Linux]]
[[Category:Linux]]

Latest revision as of 11:27, 17 July 2026

Template:Status

Template:TOC

Overview

Apt tips and tricks는 Debian/Ubuntu 기반 Linux 시스템에서 apt/dpkg 패키지를 효율적으로 관리하는 방법과 실용적인 팁을 제공합니다.

Summary

  • 무엇인가? apt/dpkg 패키지 관리 도구 활용법과 실용적인 팁 모음
  • 왜 필요한가? 패키지 설치, 업그레이드, 오프라인 설치, 커널 관리 등 일상적 시스템 관리 작업 효율화
  • 언제 사용하는가? Ubuntu/Debian 시스템 관리, 패키지 문제 해결, 오프라인 환경 설치


Purpose

이 문서가 존재하는 이유

  • Goal: apt/dpkg 패키지 관리의 실용적인 팁과 문제 해결 방법 제공
  • Scope: deb-src 설정, 오프라인 설치, 특정 패키지 업그레이드, 커널 관리, dpkg 명령어
  • Non-goals: YUM/DNF(RHEL/CentOS) 패키지 관리, 소스 코드 컴파일


Key Concepts

Concept Description Related
apt Debian/Ubuntu 기반 시스템의 고급 패키지 관리 도구 Linux
dpkg Debian 패키지 시스템의 저수준 패키지 관리 도구 apt
deb-src 소스 패키지 저장소 설정 — apt source 명령어 사용에 필요 sources.list
sources.list apt 저장소 설정 파일 — deb와 deb-src URI 포함 apt
Offline Install 인터넷 없이 패키지를 설치하는 방법 — 의존성 패키지 미리 다운로드 apt


Architecture

apt/dpkg 패키지 관리 시스템은 다음과 같은 계층으로 구성됩니다:

graph TD
    A[사용자] --> B[apt - 고급 패키지 관리]
    B --> C[dpkg - 저수준 패키지 설치]
    C --> D[/var/lib/dpkg/ - 데이터베이스]
    B --> E[/etc/apt/sources.list - 저장소 설정]
    E --> F[deb - 바이너리 패키지]
    E --> G[deb-src - 소스 패키지]
    F --> H[/var/cache/apt/archives/ - 캐시]
    G --> I[소스 코드 다운로드]


Workflow

Stage Input Output
패키지 검색 패키지명 설치 가능한 패키지 목록
패키지 설치 패키지명 시스템에 설치된 패키지
오프라인 설치 .deb 파일 + 의존성 시스템에 설치된 패키지
커널 관리 현재 커널 버전 불필요한 커널 제거
패키지 업그레이드 패키지명 업그레이드된 패키지


Detailed Explanation

deb-src URI 설정

sources.list에 deb-src URI가 없으면 `apt source` 명령어가 작동하지 않습니다. 다음 줄을 sources.list에 추가하세요:

deb-src http://in.archive.ubuntu.com/ubuntu lunar main restricted

Ubuntu — 설치된 패키지 목록 및 다운로드

모든 설치된 패키지를 /var/cache/apt/archives에 다운로드:

#dpkg -l | grep "^ii"| awk '{print $2} ' | xargs sudo apt-get -y --force-yes install --reinstall --download-only

오프라인 패키지 설치

네트워크 관련 패키지를 실수로 삭제한 경우 시스템 재설치 없이 오프라인으로 설치할 수 있습니다.

# 의존성 확인
$ apt-cache depends netplan.io

# 의존성 패키지 다운로드
$ apt download <package>

# USB에 복사하여 대상 시스템에 설치
$ sudo dpkg -i <netplan.io deb package>

특정 패키지만 업그레이드

sudo apt-get install --only-upgrade <packagename>

_hold된 패키지 확인

apt-mark showhold

오래된 커널 제거

# 현재 커널 목록 파일화
$dpkg --list | egrep -i --color 'linux-image|linux-headers|linux-modules' | awk '{ print $2 }' > kernels.txt

# 현재 사용 중인 커널 제외
$grep -v $(uname -r) kernels.txt > kernels_to_delete.txt

# 현재 커널이 삭제 목록에 없는지 확인 (필수!)
grep $(uname -r) kernels_to_delete.txt

# 불필요한 커널 일괄 제거
$cat kernels_to_delete.txt | xargs sudo apt purge -y

실용적인 dpkg 명령어

dpkg는 많은 옵션을 제공하며, 이 페이지에서 가장 실용적인 dpkg 명령어를 확인할 수 있습니다.


Configuration

# /etc/apt/sources.list 예시
deb http://in.archive.ubuntu.com/ubuntu lunar main restricted
deb-src http://in.archive.ubuntu.com/ubuntu lunar main restricted
deb http://in.archive.ubuntu.com/ubuntu lunar-updates main restricted
deb-src http://in.archive.ubuntu.com/ubuntu lunar-updates main restricted


Examples

Example 1: 오프라인 설치

# 의존성 확인
$ apt-cache depends netplan.io
netplan.io
  Depends: libc6
  Depends: libglib2.0-0
  Depends: libnetplan0
  Depends: libsystemd0
  Depends: libuuid1
  Depends: iproute2
  Depends: python3
  Depends: python3-yaml
  Depends: python3-netifaces
  Depends: systemd

# 의존성 패키지 다운로드
$ apt download netplan.io

# USB에 복사하여 대상 시스템에 설치
$ sudo dpkg -i netplan.io*.deb

Example 2: 오래된 커널 제거

# 현재 커널 목록 파일화
$dpkg --list | egrep -i --color 'linux-image|linux-headers|linux-modules' | awk '{ print $2 }' > kernels.txt

# 현재 사용 중인 커널 제외
$grep -v $(uname -r) kernels.txt > kernels_to_delete.txt

# 현재 커널이 삭제 목록에 없는지 확인
grep $(uname -r) kernels_to_delete.txt

# 불필요한 커널 일괄 제거
$cat kernels_to_delete.txt | xargs sudo apt purge -y


Best Practices

  • sources.list에 deb-src URI 추가 — 소스 패키지 다운로드 및 컴파일 준비
  • 정기적인 커널 정리 — 불필요한 커널 제거로 부트 파티션 공간 확보
  • 오프라인 설치 패키지 미리 준비 — 네트워크 관련 패키지 삭제 시 대비
  • apt-mark showhold로 hold된 패키지 확인 — 의도치 않은 업그레이드 방지
  • dpkg --verify로 설치된 패키지 무결성 확인


Limitations

  • apt는 Debian/Ubuntu 기반 시스템에만 적용 — RHEL/CentOS는 YUM/DNF 사용
  • 오프라인 설치 시 의존성 해결이 복잡할 수 있음
  • deb-src 설정 시 네트워크 접근 권한 필요
  • 오래된 커널 제거 시 현재 커널이 삭제 목록에 없는지 반드시 확인 필요


References


Related Pages

Knowledge Graph

Related

LinuxServerHardwareNetwork