rubric/modules/linuxmodules/linux_packages.go
2026-04-06 11:02:36 +03:00

191 lines
9.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package linuxmodules
import (
"fmt"
"rubric/utils"
)
var PackagesModule = Module{
Key: "packages",
Aliases: []string{"pkg", "dnf", "apt", "пакеты"},
Title: "Пакетный менеджер",
Description: "Тема 47: dnf (RHEL/Fedora) и apt (Debian/Ubuntu)",
Run: showPackages,
}
func showPackages() {
utils.Header("Linux — Пакетный менеджер")
utils.Section("47. Пакетные менеджеры: dnf и apt")
utils.Println("Пакетный менеджер — инструмент установки, обновления и удаления ПО.")
utils.Println("Решает зависимости автоматически, загружает из репозиториев.")
fmt.Println()
utils.Println(utils.ColorBold + "Семейства дистрибутивов и их менеджеры:" + utils.ColorReset)
utils.Code(`RHEL / CentOS / Fedora / Rocky / AlmaLinux:
dnf (современный) / yum (устаревший)
Формат пакетов: .rpm
Репозитории: /etc/yum.repos.d/*.repo
Debian / Ubuntu / Linux Mint:
apt (фронтенд) / dpkg (низкий уровень)
Формат пакетов: .deb
Репозитории: /etc/apt/sources.list, /etc/apt/sources.list.d/
Arch Linux:
pacman
Alpine Linux:
apk`)
// ─── dnf ──────────────────────────────────────────────────────
utils.Section("dnf — RHEL / Fedora / CentOS")
utils.Println(utils.ColorBold + "Основные операции:" + utils.ColorReset)
utils.Command("dnf search nginx", "поиск пакета")
utils.Command("dnf info nginx", "информация о пакете")
utils.Command("dnf install nginx", "установить")
utils.Command("dnf install nginx -y", "без подтверждения")
utils.Command("dnf remove nginx", "удалить")
utils.Command("dnf update", "обновить все пакеты")
utils.Command("dnf update nginx", "обновить конкретный")
utils.Command("dnf upgrade --refresh", "обновить с принудительным обновлением метаданных")
utils.Command("dnf check-update", "показать доступные обновления")
fmt.Println()
utils.Println(utils.ColorBold + "Запросы и история:" + utils.ColorReset)
utils.Command("dnf list installed", "установленные пакеты")
utils.Command("dnf list available", "доступные пакеты")
utils.Command("dnf list | grep nginx", "найти в списке")
utils.Command("dnf provides /usr/bin/python3", "какой пакет предоставляет файл")
utils.Command("dnf provides '*/Makefile'", "поиск по glob")
utils.Command("rpm -ql nginx", "файлы установленного пакета")
utils.Command("rpm -qf /etc/nginx/nginx.conf", "какому пакету принадлежит файл")
utils.Command("rpm -qi nginx", "информация об установленном пакете")
utils.Command("dnf history", "история операций")
utils.Command("dnf history undo 5", "отменить операцию №5")
fmt.Println()
utils.Println(utils.ColorBold + "Группы пакетов:" + utils.ColorReset)
utils.Command("dnf group list", "список групп")
utils.Command("dnf group info 'Development Tools'", "информация о группе")
utils.Command("dnf group install 'Development Tools'", "установить группу")
utils.Command("dnf group remove 'Development Tools'", "удалить группу")
fmt.Println()
utils.Println(utils.ColorBold + "Репозитории:" + utils.ColorReset)
utils.Code(`# Список репозиториев:
dnf repolist
dnf repolist all # включая отключённые
# Включить/выключить репозиторий:
dnf config-manager --enable epel
dnf config-manager --disable crb
# Добавить репозиторий:
dnf install epel-release # EPEL (Extra Packages for Enterprise Linux)
dnf config-manager --add-repo https://rpm.example.com/example.repo
# Установить из конкретного репозитория:
dnf install nginx --repo=epel
# Файл репозитория (/etc/yum.repos.d/myrepo.repo):
[myrepo]
name=My Repository
baseurl=https://repo.example.com/rhel/$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.example.com/RPM-GPG-KEY-myrepo`)
utils.Println(utils.ColorBold + "Кэш и модули:" + utils.ColorReset)
utils.Command("dnf clean all", "очистить кэш")
utils.Command("dnf makecache", "обновить кэш метаданных")
utils.Command("dnf autoremove", "удалить ненужные зависимости")
utils.Command("dnf module list", "список модулей (AppStream)")
utils.Command("dnf module install nodejs:18", "установить модуль nodejs версии 18")
utils.Command("dnf module enable postgresql:15", "включить модуль")
// ─── apt ──────────────────────────────────────────────────────
utils.Section("apt — Debian / Ubuntu")
utils.Println(utils.ColorBold + "Основные операции:" + utils.ColorReset)
utils.Command("apt search nginx", "поиск пакета")
utils.Command("apt show nginx", "информация о пакете")
utils.Command("apt install nginx", "установить")
utils.Command("apt install nginx -y", "без подтверждения")
utils.Command("apt remove nginx", "удалить (конфиги остаются)")
utils.Command("apt purge nginx", "удалить с конфигами")
utils.Command("apt update", "обновить индекс репозиториев (метаданные)")
utils.Command("apt upgrade", "обновить установленные пакеты")
utils.Command("apt full-upgrade", "обновить, может удалять и устанавливать новые")
utils.Command("apt dist-upgrade", "аналог full-upgrade")
utils.Command("apt autoremove", "удалить ненужные зависимости")
utils.Command("apt clean", "очистить кэш скачанных пакетов")
utils.Command("apt autoclean", "очистить устаревший кэш")
fmt.Println()
utils.Println(utils.ColorBold + "Запросы:" + utils.ColorReset)
utils.Command("apt list --installed", "установленные пакеты")
utils.Command("apt list --upgradable", "пакеты с доступными обновлениями")
utils.Command("dpkg -l nginx", "статус установленного пакета")
utils.Command("dpkg -L nginx", "файлы установленного пакета")
utils.Command("dpkg -S /etc/nginx/nginx.conf", "какому пакету принадлежит файл")
utils.Command("dpkg -s nginx", "информация об установленном пакете")
fmt.Println()
utils.Println(utils.ColorBold + "Репозитории (Debian/Ubuntu):" + utils.ColorReset)
utils.Code(`# Конфиг: /etc/apt/sources.list
# Ubuntu 22.04:
deb http://ru.archive.ubuntu.com/ubuntu jammy main restricted
deb http://ru.archive.ubuntu.com/ubuntu jammy-updates main restricted
deb http://security.ubuntu.com/ubuntu jammy-security main restricted
# Добавить PPA (Ubuntu):
add-apt-repository ppa:ondrej/php
apt update
apt install php8.3
# Добавить сторонний репозиторий (пример nginx):
# 1. Импортировать GPG-ключ:
curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
-o /etc/apt/keyrings/nginx.gpg
# 2. Добавить репозиторий:
echo "deb [signed-by=/etc/apt/keyrings/nginx.gpg] \
http://nginx.org/packages/ubuntu $(lsb_release -cs) nginx" \
> /etc/apt/sources.list.d/nginx.list
# 3. Обновить и установить:
apt update && apt install nginx
# Файл в /etc/apt/sources.list.d/: формат .list или .sources (deb822)`)
utils.Println(utils.ColorBold + "Низкоуровневые операции (dpkg):" + utils.ColorReset)
utils.Code(`# Установить .deb файл:
dpkg -i package.deb
apt install -f # исправить зависимости после dpkg
# Удалить:
dpkg -r package # без конфигов
dpkg -P package # с конфигами (purge)
# Reconfigure (перенастроить):
dpkg-reconfigure tzdata
dpkg-reconfigure locales`)
utils.Println(utils.ColorBold + "Общие инструменты управления ПО:" + utils.ColorReset)
utils.Code(`# Snap (Ubuntu, кросс-дистрибутивный):
snap install code --classic
snap list
snap remove code
snap refresh
# Flatpak (кросс-дистрибутивный):
flatpak install flathub org.gimp.GIMP
flatpak run org.gimp.GIMP
flatpak list
# pip (Python):
pip install requests
pip install -r requirements.txt
pip list
# npm (Node.js):
npm install -g pm2
npm list -g`)
utils.Footer()
}