Apt tips and tricks: Difference between revisions

From HPCWIKI
Jump to navigation Jump to search
No edit summary
(Fix: remove --- horizontal lines (12 removed))
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Status
|status=Draft
|owner=Knowledge Agent
|last_update=2026-07-15
|review=Pending
}}


== You must put some 'deb-src' URIs in your sources.list<ref>https://www.tecmint.com/fix-deb-src-uris-in-your-sources-list-error/</ref> ==
{{TOC}}
Caused by there is no dev-src syntax in sources.list on Debian-based [[Linux]] distributions. especially when you try to run.


Source packages contain the source code used to build the binary packages available for installation. Enabling the source repositories allows users to fetch the source code of packages for inspection, modification, or recompilation.
== Overview ==


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


=== Summary ===


'''etc/apt/sources.list has''' lines that begin with <code>"deb"</code> and <code>"deb-src"</code> followed by a repository URL. '''C'''omment out relevant URL or add deb-src to use $apt source command, for example,  
* 무엇인가? apt/dpkg 패키지 관리 도구 활용법과 실용적인 팁 모음
* 왜 필요한가? 패키지 설치, 업그레이드, 오프라인 설치, 커널 관리 등 일상적 시스템 관리 작업 효율화
* 언제 사용하는가? Ubuntu/Debian 시스템 관리, 패키지 문제 해결, 오프라인 환경 설치


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


== Ubuntu - list of installed packages and downloads<ref>https://askubuntu.com/questions/86358/how-to-obtain-installed-package-files/86413#86413</ref> ==
== Purpose ==
 
이 문서가 존재하는 이유
 
* Goal: apt/dpkg 패키지 관리의 실용적인 팁과 문제 해결 방법 제공
* Scope: deb-src 설정, 오프라인 설치, 특정 패키지 업그레이드, 커널 관리, dpkg 명령어
* Non-goals: YUM/DNF(RHEL/CentOS) 패키지 관리, 소스 코드 컴파일
 
 
== Key Concepts ==
 
{| class="wikitable"
! 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 패키지 관리 시스템은 다음과 같은 계층으로 구성됩니다:
 
<syntaxhighlight lang="mermaid">
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[소스 코드 다운로드]
</syntaxhighlight>
 
 
== Workflow ==
 
{| class="wikitable"
! Stage
! Input
! Output
|-
| 패키지 검색
| 패키지명
| 설치 가능한 패키지 목록
|-
| 패키지 설치
| 패키지명
| 시스템에 설치된 패키지
|-
| 오프라인 설치
| .deb 파일 + 의존성
| 시스템에 설치된 패키지
|-
| 커널 관리
| 현재 커널 버전
| 불필요한 커널 제거
|-
| 패키지 업그레이드
| 패키지명
| 업그레이드된 패키지
|}
 
 
== Detailed Explanation ==
 
=== deb-src URI 설정 ===
 
sources.list에 deb-src URI가 없으면 `apt source` 명령어가 작동하지 않습니다. 다음 줄을 sources.list에 추가하세요:
 
<syntaxhighlight lang="text">
deb-src http://in.archive.ubuntu.com/ubuntu lunar main restricted
</syntaxhighlight>
 
=== Ubuntu — 설치된 패키지 목록 및 다운로드 ===
 
모든 설치된 패키지를 /var/cache/apt/archives에 다운로드:
 
<syntaxhighlight lang="bash">
#dpkg -l | grep "^ii"| awk '{print $2} ' | xargs sudo apt-get -y --force-yes install --reinstall --download-only
</syntaxhighlight>
 
=== 오프라인 패키지 설치 ===
 
네트워크 관련 패키지를 실수로 삭제한 경우 시스템 재설치 없이 오프라인으로 설치할 수 있습니다.
 
<syntaxhighlight lang="bash">
# 의존성 확인
$ apt-cache depends netplan.io
 
# 의존성 패키지 다운로드
$ apt download <package>
 
# USB에 복사하여 대상 시스템에 설치
$ sudo dpkg -i <netplan.io deb package>
</syntaxhighlight>
 
=== 특정 패키지만 업그레이드 ===
 
<syntaxhighlight lang="bash">
sudo apt-get install --only-upgrade <packagename>
</syntaxhighlight>
 
===_hold된 패키지 확인 ===
 
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Download all the installed packages into /var/cache/apt/archives (Ubuntu)
apt-mark showhold
</syntaxhighlight>
 
=== 오래된 커널 제거 ===
 
<syntaxhighlight lang="bash">
# 현재 커널 목록 파일화
$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
</syntaxhighlight>
 
=== 실용적인 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 ==


#dpkg -l | grep "^ii"| awk ' {print $2} ' | xargs sudo apt-get -y --force-yes install --reinstall --download-only
<syntaxhighlight lang="text">
# /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
</syntaxhighlight>
</syntaxhighlight>


== Offline package install ==
 
In case accedentially remove essentional packages from running OS especially for network releated one. offline package installation is important instead of reinstall the system.  To install package offline, the package with all dependencies should be ready to use offline.<syntaxhighlight lang="bash">
== Examples ==
# find all dependency with apt-cache
 
=== Example 1: 오프라인 설치 ===
 
<syntaxhighlight lang="bash">
# 의존성 확인
$ apt-cache depends netplan.io
$ apt-cache depends netplan.io
netplan.io
netplan.io
Line 30: Line 194:
   Depends: libuuid1
   Depends: libuuid1
   Depends: iproute2
   Depends: iproute2
    iproute2:i386
   Depends: python3
   Depends: python3
   Depends: python3-yaml
   Depends: python3-yaml
   Depends: python3-netifaces
   Depends: python3-netifaces
   Depends: systemd
   Depends: systemd
    systemd:i386
  Conflicts: netplan
  Breaks: network-manager
  Breaks: nplan
|Suggests: network-manager
  Suggests: wpasupplicant
    wpasupplicant:i386
  Replaces: nplan


# download all dependency packages
# 의존성 패키지 다운로드
$ apt download <package>
$ apt download netplan.io


# copy them to USB and mount the USB to the target systemd
# USB에 복사하여 대상 시스템에 설치
$ sudo dpkg -i <netplan.io deb package>
$ sudo dpkg -i netplan.io*.deb
</syntaxhighlight>
</syntaxhighlight>


== Only upgrade specific package ==
=== Example 2: 오래된 커널 제거 ===
<code>sudo apt-get install --only-upgrade <packagename></code>


== Show holding package ==
<syntaxhighlight lang="bash">
<code>apt-mark showhold</code>
# 현재 커널 목록 파일화
 
== Remove old kernel ==
One of the best and simple way from this thead<ref>https://askubuntu.com/questions/1253347/how-to-easily-remove-old-kernels-in-ubuntu-20-04-lts</ref> <syntaxhighlight lang="bash">
#list up all the current kernels you have on a file.
$dpkg --list | egrep -i --color 'linux-image|linux-headers|linux-modules' | awk '{ print $2 }' > kernels.txt
$dpkg --list | egrep -i --color 'linux-image|linux-headers|linux-modules' | awk '{ print $2 }' > kernels.txt


#Filter your currently used kernel out of the file using grep.
# 현재 사용 중인 커널 제외
$grep -v $(uname -r) kernels.txt > kernels_to_delete.txt
$grep -v $(uname -r) kernels.txt > kernels_to_delete.txt


#Verify your current kernel is not present in the delete list. Don't skip this. Ensures you don't mistakenly delete all the kernels.
# 현재 커널이 삭제 목록에 없는지 확인
grep $(uname -r) kernels_to_delete.txt
grep $(uname -r) kernels_to_delete.txt


#Delete all the unused kernels in one go.
# 불필요한 커널 일괄 제거
$cat kernels_to_delete.txt | xargs sudo apt purge -y
$cat kernels_to_delete.txt | xargs sudo apt purge -y
</syntaxhighlight>
== Best Practices ==


</syntaxhighlight>
* sources.list에 deb-src URI 추가 — 소스 패키지 다운로드 및 컴파일 준비
* 정기적인 커널 정리 — 불필요한 커널 제거로 부트 파티션 공간 확보
* 오프라인 설치 패키지 미리 준비 — 네트워크 관련 패키지 삭제 시 대비
* apt-mark showhold로 hold된 패키지 확인 — 의도치 않은 업그레이드 방지
* dpkg --verify로 설치된 패키지 무결성 확인
 
 
== Limitations ==
 
* apt는 Debian/Ubuntu 기반 시스템에만 적용 — RHEL/CentOS는 YUM/DNF 사용
* 오프라인 설치 시 의존성 해결이 복잡할 수 있음
* deb-src 설정 시 네트워크 접근 권한 필요
* 오래된 커널 제거 시 현재 커널이 삭제 목록에 없는지 반드시 확인 필요


== Practical dpkg Command ==
dpkg has many options to run and [https://www.cyberithub.com/21-practical-dpkg-command-examples-for-linux-beginners/#Example_13_How_to_Verify_all_the_Installed_Packages this page] describes most practical dpkg commands


== References ==
== References ==
<references />
 
* https://www.tecmint.com/fix-deb-src-uris-in-your-sources-list-error/
* https://askubuntu.com/questions/86358/how-to-obtain-installed-package-files/86413#86413
* https://askubuntu.com/questions/1253347/how-to-easily-remove-old-kernels-in-ubuntu-20-04-lts
* https://www.cyberithub.com/21-practical-dpkg-command-examples-for-linux-beginners/
 
 
== Related Pages ==
 
* [[Linux]]
* [[apt]]
* [[dpkg]]
* [[sources.list]]
* [[Ubuntu]]
* [[Kernel Management]]
 
 
[[Category:Linux]]
== Knowledge Graph ==
 
Related
 
→ [[Linux]]
→ [[Server]]
→ [[Hardware]]
→ [[Network]]
 
[[Category:Reference]]

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