Linux alpine apt get

Содержание
  1. Comparison with other distros
  2. Contents
  3. Package management
  4. Updating package database
  5. Showing available updates
  6. Updating a particular package
  7. Installing packages
  8. Reinstalling particular packages
  9. Searching the package database
  10. Removing packages
  11. Only downloading packages
  12. Cleaning up downloaded packages
  13. Reverse dependencies
  14. Runlevel & Initscripts
  15. Directories and files
  16. Runlevel management
  17. Config Files
  18. /etc/portage/make.conf and use flags
  19. Architectures and repositories
  20. Network
  21. Comparison chart/Rosetta Stone
  22. 10 Alpine Linux apk Command Examples
  23. Purpose
  24. Syntax
  25. Alpine Linux apk command examples
  26. How to update the package list
  27. How to search for package(s)
  28. To list all packages available, along with their descriptions
  29. How do I search package by wildcards?
  30. How to install a package(s) by name
  31. Interactive install or upgrade
  32. Simulation with apk command
  33. How to hold a specific package back and not upgrade it
  34. How do install a local .apk file package?
  35. How to remove or delete a package(s) by name
  36. How do I delete old packages caches on Alpine Linux?
  37. How to upgrade running Alpine Linux
  38. How do I upgrade selected packages only?
  39. How do I list installed packages?
  40. Find out which package a file belongs to..
  41. List contents of the PACKAGE
  42. Check if PACKAGE is installed
  43. List packages that the PACKAGE depends on
  44. List all packages depending on PACKAGE
  45. Show installed size of PACKAGE
  46. Print description for PACKAGE
  47. Print all information about PACKAGE
  48. How do I see statistics about repositories and installations?
  49. apk command options and examples
  50. See also

Comparison with other distros

Even if Alpine is designed to run from RAM, it has some similarities in package management with both Gentoo and Debian. This page outlines those similarities and differences, to help Debian and Gentoo users use Alpine.

Contents

Package management

Where Gentoo has portage and emerge; Debian has, among others, apt; Alpine uses apk-tools. This section compares how apk-tools is used, in comparison to apt and emerge.

Note that Gentoo is source-based, just like ports in FreeBSD are, while Debian uses pre-compiled binaries. Alpine is compiled using Gentoo’s portage, but Alpine itself uses its own apk-tools binary package which is more similar to FreeBSD’s binary packages.

Updating package database

Gentoo will update the build-from-source scripts and the updating of the database takes much more time than updating the database for Debian or Alpine.

Showing available updates

Show which packages have an update available:

Updating a particular package

Installing packages

For source compile, see the Aports tree and the abuild tool.

Debian source compile:

(optional: customize the build by modifying the debian/rules makefile) (or set environmental variables like DEB_BUILD_OPTIONS) (note that this will make your bug reports invalid to the maintainer)

Simplified source compile:

(the packages are automatically generated using the -b switch above)

Note: This process can be used to backport packages from testing and unstable by simply adding their respective source repositories to sources.list, which is similar to adding

x86 to package.keywords in Gentoo. This is explored further in the «Architectures and repositories» section below.

Reinstalling particular packages

Note: You rarely need to reinstall a package on Debian

Searching the package database

Alpine will only search package names.

To search the package names and descriptions:

Note: On Gentoo, it’s actually much better to install and use either the esearch package or the eix package to do a search. You use them like this:

Both emerge and apt-cache search support regular expressions.

To get the long package information on Debian (searching only in package names):

Removing packages

apk del will remove configuration files when the —purge flag is used. Make sure you have backups of your configuration files. (Using rcs might be an idea)

You will mostly like to take a quick look at the dependencies before you remove packages recursively.

To see dependencies for a package, use:

To see if package is required by other packages (is a dependency for another packages), use:

or to remove along with all configuration files

Only downloading packages

This can be useful e.g. if you’re on a dial-up connection and want to download everything first and install later.

Читайте также:  Samsung mtp port драйвер для windows

Cleaning up downloaded packages

Compressed packages that were downloaded for installation can easily consume gigabytes of storage space.

Alpine will clean up packages automatically.

To only remove outdated packages you will need to install the gentoolkit package and use eclean:

Cleaning temporary files from emerging packages:

Only remove outdated packages:

Reverse dependencies

apk-tools will take care of reverse dependencies.

Reverse dependencies are a major drawback of Gentoo’s current portage implementation: It does not take care of them at all at the moment. If you use the unsafe —unmerge argument, this means that you can uninstall packages needed by others without being warned about it. E.g. you can remove the X server package without portage warning you that KDE (which you have installed as well) depends on it. This way you can actually break your entire system (e.g. by removing glibc).

can fix broken dependencies broken by emerge —depclean

Recent versions of portage include library tracking and preservation with the preserved-libs feature. Portage will notify you to run

to help rebuild binaries that might otherwise become broken.

Reverse dependencies are taken care of by dpkg.

Runlevel & Initscripts

Runlevels work pretty conventionally on Debian (see details: systemd). On Alpine and Gentoo, they are a bit different.

Directories and files

In Debian, runlevels are named conventionally (0-6 and S). They are represented by directories in /etc/ called rc*.d (when the default sysv-rc boot loader package is installed; file-rc can be installed instead, and then the relevant file is runlevel.conf).

In Gentoo, runlevels have the same names, but these are mapped to more self explanatory ones (in /etc/inittab): «boot», «default», «nonetwork», with the option to add more. The directories that represent them are in /etc/runlevels/:

  • /etc/runlevels/boot
  • /etc/runlevels/default
  • /etc/runlevels/nonetwork

In Gentoo, if a service is not explicitly started in a runlevel, it is stopped when switching to that runlevel! There is no explicit stopping of runlevels as in Debian (/etc/rc?.d/K??service).

In both Debian and Gentoo, which things are started (and stopped) in which runlevels is controlled by links in the runlevel directories to scripts in /etc/init.d/, e.g.: Gentoo

In Alpine, runlevels work like they do in Gentoo:

  • /etc/runlevels/boot
  • /etc/runlevels/default
  • /etc/runlevels/sysinit
  • /etc/runlevels/nonetwork
  • /etc/runlevels/shutdown

Runlevel management

To manage which things to start in which runlevels, use the following commands:

To see current status of services in runlevels, do:

To add sshd to default runlevel, do:

The -k option will make sure sshd is stopped when shutting down or reboot. To remove sshd from all runlevels do:

To add the cupsd to the default runlevel, do:

To remove alsasound from the boot runlevel, do:

Configure cupsd to be started in runlevels 2, 3, 4, 5, and stopped in 0, 1, 6, with sequence code 20:

Remove cupsd from all runlevels:

Config Files

/etc/portage/make.conf and use flags

While in Gentoo there’s a large number of configuration files which control the behaviour of the package management system, there are comparatively fewer in Debian, as there is no need to dictate how to compile software which is downloaded and tweak/alter it. In Gentoo, the file /etc/portage/make.conf is used for much configuration; this includes USE flags, which influence which elements of packages are compiled, and which libraries to build support for — common USE flags (USE or -USE to specifically negate support) include ‘gtk gnome’ for Gnome users (and a corresponding -qt -kde -arts) and ‘qt kde arts’ for KDE users. A Gentoo user’s complete set of use flags may look something like this:

USE=»-kde -arts -qt xv truetype bluetooth crypt slang readline gpm berkdb mmx gdbm tcpd pam libwww ssl nls ethereal perl python esd gif imlib sdl oggvorbis mpeg gnome gtk X motif opengl avi png tiff nptl pcmcia nptl ldap eds»

Architectures and repositories

Also in /etc/portage/make.conf is the ACCEPT_KEYWORDS setting, with (for an X86-based processor) two settings, x86 for stabler packages, and

x86 for bleeding edge packages. It is however not recommended to make this change in /etc/portage/make.conf. Rather configure this per-package in /etc/portage/package.accept_keywords. It’s enough to put a line into that file naming the package (for example ‘app-foo/bar’). That file might look like this:

Читайте также:  Linux дистрибутив для слабой машины

The last line says, that only version 4.3-r1 should be unmasked. Older and newer versions will still be ignored.

Note for non-x86 users: The keywords x86 and

x86 can of course be replaced by sparc and

sparc for example.

Setting this in Debian is slightly more complicated, and is accomplished by setting different ‘repositories’ in /etc/apt/sources.list — along with which ‘tree’ to use for packages; in Debian, these are stable, testing, and unstable. An /etc/apt/sources.list file for a debian testing user may look something like this:

Alternatively, /etc/apt/sources.list can contain any number of repositories for any trees, and a default tree (this can be overridden using the -t switch on the command line) in /etc/apt/apt.conf:

Per-package settings go in /etc/apt/preferences, somewhat like Gentoo’s /etc/portage/package.keywords.

Network

Alpine uses /etc/network/interfaces, just like Debian. The main reason is because this is the way busybox does it.

Note that this has changed recently. For more information please refer to http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=4

Comparison chart/Rosetta Stone

This chart shows how some standard things are done in Alpine compared to other distributions.

Источник

10 Alpine Linux apk Command Examples

I am new Alpine Linux system admin user. How do I use apk command line utility for the package management on Apline Linux server running in cloud or a Linux container? How can I use the apk command for the package management?

apk command details
Description APK command
Category Package Manager
Difficulty Easy
Root privileges Yes
Est. reading time 10 minutes
Table of contents
  • » Syntax
  • » Examples
  • » Update the package list
  • » Search for package
  • » Install a package
  • » Remove/delete a package
  • » Upgrade running system
  • » List installed packages
  • » Show statistics
  • » See also

Purpose

Use apk for installing, upgrading, configuring, and removing apps/programs for an Alpine Linux operating system in a consistent manner.

Syntax

The basic syntax is as follows:

apk [options] command
apk [options] command pkgName
apk [options] command pkgName1 pkgName2

Alpine Linux apk command examples

Let us see how to use the apk command to install security updates or new set of packages on an Alpine Linux server.

How to update the package list

To update your package list, enter:
# apk update
Sample outputs:

Fig.01: How to update the package list in Alpine Linux

How to search for package(s)

The syntax is:
# apk search pkgName
For example, search a package named htop, run:
# apk search htop
Sample outputs:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

To search and display description:
# apk search -v -d ‘htop’
Sample outputs:

To list all packages available, along with their descriptions

# apk search -v
Sample outputs:

How do I search package by wildcards?

The syntax is as follows to search all php7 packages or php5 packages:
# apk search -v ‘php5*’
### OR ###
# apk search -v ‘php7*’
Sample outputs:

How to install a package(s) by name

The syntax is:
# apk add pkgName
# apk add pkgName1 pkgName2
To install a htop package, run:
# apk add htop
Sample outputs:

To install Apache2 along with PHP7 and modules, run:
# apk add apache2 php7-apache2 php7-gd php7-mysqli
Sample outputs:

Interactive install or upgrade

We can force confirmation before performing certain operations by passing the -i option:
# apk -i add nginx
# apk -i upgrade

Simulation with apk command

We can simulate the requested operation without making any changes. Helpful to see what packages will be upgrades or what will be done on the Alpine Linux system:
# apk -s command
# apk -s add nginx
# apk -s upgrade
In other words, nothing was installed or upgraded on the system, but you will know precisely what apk was about to do.

How to hold a specific package back and not upgrade it

If you want to upgrade Alpine Linux system, but keep or hold a specific package add version number. For instance, to hold the bash package to the version 5.0.0-r0 level or lower, run:
# apk add bash = 5.0.0-r0
One can do regex based version matching to hold the version to a major/minor release. For example:
# apk add bash =

How do install a local .apk file package?

The syntax is as follows to add a local package named foo.apk:
# apk add —allow-untrusted /path/to/foo.apk
apk add —allow-untrusted pkg1.apk pkg2.apk

How to remove or delete a package(s) by name

The syntax is:
# apk del pkgName
# apk del pkgName1 pkgName2
To delete a htop package run:
# apk del htop
Sample outputs:

How do I delete old packages caches on Alpine Linux?

To remove out older versions of packages, run the clean command as follows:
# apk cache clean
## or ##
# apk -v cache clean
One can also clean cache and download missing packages in one step:
# apk cache -v sync

How to upgrade running Alpine Linux

The syntax is:
# apk update && apk upgrade
You can create a bash shell alias as follows in

/.bashrc
# echo «alias update=’apk update && apk upgrade'» >> /.bashrc
Run it as follows:
# update

How do I upgrade selected packages only?

The syntax is
# apk add -u pkgName
To upgrade a htop only package:
# apk update
# apk add -u htop

How do I list installed packages?

The syntax is:
# apk info
# apk info -vv | grep ‘foo’
# apk info -vv | sort

Fig.02: How do I show/list installed packages in Alpine Linux

Find out which package a file belongs to..

to determine which package a file named /etc/passwd or /sbin/apk belongs to:
# apk info —who-owns /etc/passwd
/etc/passwd is owned by alpine-baselayout-3.0.4-r0
# apk info —who-owns /sbin/apk
/sbin/apk is owned by apk-tools-2.6.8-r2

List contents of the PACKAGE

# apk -L info pkgName
# apk -L info htop
Sample outputs:

Check if PACKAGE is installed

# apk -e info pkgName
#############################################
### find out if atop PACKAGE is installed ###
#############################################
# apk -e info atop
No output displayed if PACKAGE is NOT installed.

List packages that the PACKAGE depends on

# apk -R info atop
# apk -R info atop
Sample outputs:

List all packages depending on PACKAGE

# apk info -r pkgName
# apk info -r bash
Sample outputs:

Show installed size of PACKAGE

# apk info -s pkgName
# apk info -s atop
Sample outputs:

# apk info -d pkgName
# apk info -d bash
Sample outputs:

# apk info -a pkgName
# apk info -a bash
Sample outputs:

How do I see statistics about repositories and installations?

Run the command:
# apk stats
Sample outputs:

apk command options and examples

Table 1: Options summary
Command Usage Example
apk update Update the package list apk update
apk upgrade Upgrade the system apk update
apt ugrade
apk add pkg Add a package apk add apache
apk del pkg Delete a package apk del nginx
apk search -v Search for packages apk search -v
apk search -v -d ‘nginx* ‘
apk search -v ‘apache*’
apk info List all installed pacakges apk info
apk fix Repair package or upgrade it without modifying main dependencies apk fix
apk policy pkg Show repository policy for packages apk policy bash
apk stats Show statistics about repositories and installations apk stats

See also

You learned about apk command and everyday examples to add, remove and manage packages on Alpine Linux. See also:

  • /etc/apk/repositories file.
  • apk man page

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Читайте также:  Linux как запустить бинарники
Оцените статью