クイックリファレンス

Ubuntu チートシート(APT・dpkg・systemd)

Ubuntu / Debian Linux のクイックリファレンス:APT パッケージ管理、dpkg コマンド、パッケージキャッシュ掃除、systemd サービス制御を網羅。

· 公開日

APT と dpkg によるパッケージ管理

APT コマンド

# Update repository package indexes
sudo apt update

# Upgrade installed packages to newest versions
sudo apt upgrade -y

# Search for a package by keyword
apt search nginx

# Install package
sudo apt install nginx -y

# Remove package keeping configuration
sudo apt remove nginx

# Purge package and configuration files
sudo apt purge nginx

dpkg コマンド

# Identify which package owns a specific binary or file
dpkg -S $(which nginx)

# List all files installed by a package
dpkg -L nginx

# Install a local .deb package file
sudo dpkg -i package.deb

# Show status and details of installed package
dpkg -s nginx

# List all installed packages
dpkg --get-selections

パッケージキャッシュ

ダウンロードされたパッケージアーカイブは以下のディレクトリにキャッシュされます:

/var/cache/apt/archives/

不要になった古いパッケージをキャッシュから削除:

sudo apt clean
sudo apt autoremove -y

systemd によるサービス管理

# Check service status
systemctl status nginx

# Start / stop / restart service
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

# Enable service to launch at system boot
sudo systemctl enable nginx

関連テーマ