One place for hosting & domains


      How to Use APT to Manage Packages in Debian and Ubuntu

      Advanced Package Tool, more commonly known as
      APT, is a package management system for Ubuntu, Debian, Kali Linux, and other Debian-based Linux distributions. It acts as a front-end to the lower-level
      dpkg package manager, which is used for installing, managing, and providing information on .deb packages. In addition to these functions, APT interfaces with repositories to obtain packages and also provides very efficient dependency management.

      Most distributions that use APT also include a collection of command-line tools that can be used to interface with APT. These tools include apt-get, apt-cache, and the newer apt, which essentially combines both of the previous tools with some modified functionality. Other package managers and tools also exist for interacting with APT or dpkg. A popular one is called
      Aptitude. Aptitude includes both a command-line interface as well as an interactive user interface. While it does offer advanced functionality, it is not commonly installed by default and is not covered in this guide.

      This guide aims to walk you through using APT and its command-line tools to perform common functions related to package management. The commands and examples used throughout this guide default to using the apt command. Many of the commands interchangeable with either apt-get or apt-cache, though there may be breaking differences.

      Before You Begin

      Before running the commands within this guide, you will need:

      1. A system running on Debian or Ubuntu. Other Linux distributions that employ the APT package manager can also be used. Review the
        Creating a Compute Instance guide if you do not yet have a compatible system.

      2. Login credentials to the system for either the root user (not recommended) or a standard user account (belonging to the sudo group) and the ability to access the system through
        SSH or
        Lish. Review the
        Setting Up and Securing a Compute Instance guide for assistance on creating and securing a standard user account.


      Some commands in this guide require elevated privileges and are prefixed with the sudo command. If you are logged in as the root use (not recommended), you can omit the sudo prefix if desired. If you’re not familiar with the sudo command, see the
      Linux Users and Groups guide.

      What’s the difference between apt and apt-get/apt-cache?

      While there are more similarities than differences, there are a few important points to consider when decided which command to use.

      • apt: A newer end-user tool that consolidates the functionality of both apt-get and apt-cache. Compared to the others, the apt tool is more straightforward and user-friendly. It also has some extra features, such as a status bar and the ability to list packages. Both Ubuntu and Debian recommend the apt command over apt-get and apt-cache. See
        apt Ubuntu man pages
      • apt-get and apt-cache: The apt-get command manages the installation, upgrades, and removal of packages (and their dependencies). The apt-cache command is used to search for packages and retrieve details about a package. Updates to these commands are designed to never introduce breaking changes, even at the expense of the user experience. The output works well for machine readability and these commands are best limited to use within scripts. See
        apt-get Ubuntu man pages and
        apt-cache Ubuntu man pages.

      In short, apt is a single tool that encompasses most of the functionality of other APT-specific tooling. It is designed primarily for interacting with APT as an end-user and its default functionality may change to include new features or best practices. If you prefer not to risk breaking compatibility and/or prefer to interact with plainer output, apt-get and apt-cache can be used instead, though the exact commands may vary.

      Installing Packages

      Installs the specified package and all required dependencies. Replace [package] with the name of the package you wish to install. The apt install command is interchangeable with apt-get install.

      sudo apt install [package]

      Before installing packages, it’s highly recommended to obtain updated package version and dependency information and upgrade packages and dependencies to those latest version. See
      Updating Package Information and
      Upgrading Packages for more details. These actions can be performed quickly by running the following sequence of commands:

      sudo apt update && sudo apt upgrade

      Additional options, commands, and notes:

      • Install a specific version by adding an equal sign after the package, followed by the version number you’d like to install.

        sudo apt install [package]=[version]
      • Reinstall a package and any dependencies by running the following command. This is useful if an installation for a package becomes corrupt or dependencies were somehow removed.

        sudo apt reinstall [package]

      Updating Package Information

      Downloads package information from all the sources/repositories configured on your system (within /etc/apt/sources.list). This command obtains details about the latest version for all available packages as well as their dependencies. It should be the first step before installing or upgrading packages on your system.

      sudo apt update

      This command is equivalent to apt-get update.

      Upgrading Packages

      Upgrades all packages to their latest versions, including upgrading existing dependencies and installing new ones. It’s important to note that the currently installed versions are not removed and will remain on your system.

      sudo apt upgrade

      This command is equivalent to apt-get upgrade --with-new-pkgs. Without the --with-new-pkgs option, the apt-get upgrade command only upgrades existing packages/dependencies and ignores any packages that require new dependencies to be installed.

      Before upgrading packages, it’s highly recommended to obtain updated package version and dependency information. See
      Updating Package Information for more details. These two actions can be performed together through the following sequence of commands:

      sudo apt update && sudo apt upgrade

      Additional options, commands, and notes:

      • To view a list of all available upgrades, use the list command with the --upgradable option.

        apt list --upgradeable
      • To upgrade a specific package, use the install command and append the package name. If the package is already installed, it will be upgraded to the latest version your system knows about. To only upgrade (not install) a package, use the --only-upgrade option. In the below command, replace [package] with the name of the package you wish to upgrade.

        sudo apt install --only-upgrade [package]
      • The apt full-upgrade command (equivalent to apt-get dist-upgrade) can remove packages as well as upgrade and install them. In most cases, it is not recommended to routinely run these commands. To remove unneeded packages (including kernels), use apt autoremove instead.

      Uninstalling Packages

      Removes the specified package from the system, but retains any packages that were installed to satisfy dependencies as well as some configuration files. Replace [package] with the name of the package you’d like to remove.

      sudo apt remove [package]

      To remove the package as well as any configuration files, run the following command. This can also be used to just remove configuration files for previously removed packages.

      sudo apt purge [package]

      Both of these commands are equivalent to apt-get remove and apt-get purge, respectively.

      • To remove any unused dependencies, run apt autoremove (apt-get autoremove). This is commonly done after uninstalling a package or after upgrading packages and can sometimes help in reducing disk space (and clutter).

        sudo apt autoremove

      Common Command Options

      The following options are available for most of the commands discussed on this guide.

      • Multiple packages can be taken action on together by delimiting them with a space. For example:

        sudo apt install [package1] [package2]
      • Automatically accept prompts by adding the -y or --yes option. This is useful when writing scripts to prevent any user interaction when its implicit that they wish to perform the action on the specified packages.

        sudo apt install [package] -y

      Listing Packages

      The apt list command lists all available, installed, or upgradeable packages. This can be incredibly useful for locating specific packages – especially when combined with grep or less. There is no direct equivalent command within apt-cache.

      • List all packages that are installed

        apt list --installed
      • List all packages that have an upgrade available

        apt list --upgradeable
      • List all versions of all available packages

        apt list --all-versions

      Additional options, commands, and notes:

      • Use
        grep to quickly search through the list for specific package names or other strings. Replace [string] with the package name or other term you wish to search for.

        apt list --installed | grep [string]
      • Use a content viewer like
        less to interact with the output, which may help you view or search for your desired information.

        apt list --installed | less

      Searching for Available Packages

      Searches through all available packages for the specified term or regex string.

      apt search [string]

      The command apt-cache search is similar, though the output for apt search is more user-friendly.

      Additional options, commands, and notes:

      • Use the --full option to see the full description/summary for each package.

        apt search --full [string]
      • To find packages whose titles or short/long descriptions contain multiple terms, delimit each string with a space.

        apt search [string1] [string2]

      Viewing Information About Packages

      Displays information about an installed or available package. The following command is similar to apt-cache show --no-all-versions [package].

      apt show [package]

      The information in the output includes:

      • Package: The name of the package.
      • Version: The version of the package.
      • Installed-Size: The amount of space this package consumes on the disk, not including any dependencies.
      • Depends: A list of dependencies.
      • APT-Manual-Installed: Designates if the package was manually installed or automatically installed (for instance, like as a dependency for another package). This is visible within apt (not apt-cache).
      • APT-Sources: The repository where the package information was stored. This is visible within apt (not apt-cache).
      • Description: A long description of the package.

      Adding Repositories

      A repository is a collection of packages (typically for a specific Linux distribution and version) that are stored on a remote system. This enables software distributors to store a package (including new versions) in one place and enable users to quickly install that package onto their system. In most cases, we obtain packages from a repository – as opposed to manually downloading package files.

      Information about repositories that are configured on your system are stored within /etc/apt/sources.list or the directory /etc/apt/sources.list.d/. Repositories can be added manually by editing (or adding) a sources.list configuration file, though most repositories also require adding the GPG public key to APT’s keyring. To automate this process, it’s recommended to use the
      add-apt-repository utility.

      sudo add-apt-repository [repository]

      Replace [repository] with the url to the repository or, in the case of a PPA (Personal Package Archive), the reference to that PPA.

      Once a repository has been added, you can update your package list and install the package. See
      Updating Package Information and
      Installing Packages.

      Cloning Packages to Another System

      If you wish to replicate the currently installed packages to another system without actually copying over any other data, consider using the
      apt-clone utility. This software is compatible with Debian-based systems and is available through Ubuntu’s official repository.

      1. Install apt-clone.

        sudo apt install apt-clone
      2. Create a backup containing a list of all installed packages, replacing [name] with the name of the backup (such as my-preferred-packages)

        apt-clone clone [name]

        This command creates a new file using the name provided in the last step and appending .apt-clone.tar.gz.

      3. Copy the file to your new system. See the
        Download Files from Your Linode guide or the
        File Transfer section for more information.

      4. Install apt-clone on the new system (see Step 1).

      5. Using apt-clone, run the following command to restore the packages. Replace [name] with the name used in the previous step (or whatever the file is called). If the file is located within a different directly than your current directory, adjust the command to include the path.

        sudo apt-clone restore [name].apt-clone.tar.gz

      Source link

      How To Install and Manage System Packages in Ansible Playbooks

      Part of the Series:
      How To Write Ansible Playbooks

      Ansible is a modern configuration management tool that doesn’t require the use of an agent software on remote nodes, using only SSH and Python to communicate and execute commands on managed servers. This series will walk you through the main Ansible features that you can use to write playbooks for server automation. At the end, we’ll see a practical example of how to create a playbook to automate setting up a remote Nginx web server and deploy a static HTML website to it.

      Automating the installation of required system packages is a common operational task in Ansible playbooks, since a typical application stack requires software from different sources.

      The apt module manages system packages on Debian-based operating systems such as Ubuntu, the distribution we’re using on remote nodes throughout this guide. The following playbook will update the apt cache and then make sure Vim is installed on remote nodes.

      Create a new file called playbook-09.yml in your ansible-practice directory:

      • nano ~/ansible-practice/playbook-09.yml

      Then add the following lines to the new playbook file:


      - hosts: all
        become: yes
          - name: Update apt cache and make sure Vim is installed
              name: vim
              update_cache: yes

      Save and close the file when you’re done.

      Notice that we’ve included the become directive in the beginning of the play. This is required since installing packages requires administrative system permissions.

      Removing a package is done in a similar way, the only change is that you have to define the package state to absent. The state directive has a default value of present, which will make sure that the package is installed on the system, regardless of the version. The package will be installed if not present. To assure you have the latest version of a package, you can use latest instead. This will cause apt to update the requested package if that is not on their latest version.

      Remember to provide the -K option when running this playbook, since it requires sudo permissions:

      • ansible-playbook -i inventory playbook-09.yml -u sammy -K


      BECOME password: PLAY [all] ********************************************************************************************** TASK [Gathering Facts] ********************************************************************************** ok: [] TASK [Update apt cache and make sure Vim is installed] ************************************************** ok: [] PLAY RECAP ********************************************************************************************** : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

      When installing multiple packages, you can use a loop and provide an array containing the names of the packages you want to install. The following playbook will make sure the packages vim, unzip, and curl are installed and in their latest version.

      Create a new file called playbook-10.yml in your ansible-practice directory, on your Ansible control node:

      • nano ~/ansible-practice/playbook-10.yml

      Add the following content to the new playbook file:


      - hosts: all
        become: yes
          - name: Update apt cache and make sure Vim, Curl and Unzip are installed
              name: "{{ item }}"
              update_cache: yes
              - vim
              - curl
              - unzip

      Save and close the file when you have finished.

      Then, run ansible-playbook with the same connection arguments from the previous examples, and don’t forget to include the -K option since this playbook requires administrative privileges:

      • ansible-playbook -i inventory playbook-09.yml -u sammy -K

      You’ll see output like this, indicating that the same task run through three iterations using the different values we have provided: vim, curl, and unzip:


      BECOME password: PLAY [all] *************************************************************************************************************************************** TASK [Gathering Facts] *************************************************************************************************************************** ok: [] TASK [Update apt cache and make sure Vim, Curl and Unzip are installed] ************************************************************************** ok: [] => (item=vim) ok: [] => (item=curl) changed: [] => (item=unzip) PLAY RECAP *************************************************************************************************************************************** : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

      For more details on how to manage system packages, including how to remove packages and how to use advanced apt options, you can refer to the official documentation.

      Source link

      Comment installer un logiciel sur des clusters Kubernetes avec le gestionnaire de packages Helm 3


      Helm est un gestionnaire de package pour Kubernetes qui permet aux développeurs et aux opérateurs de configurer et à déployer des applications plus facilement sur les clusters Kubernetes.

      Dans ce tutoriel, vous allez configurer Helm 3 et l’utiliser pour installer, reconfigurer, revenir en arrière et supprimer une instance de l’application Kubernetes Dashboard. Le dashboard (tableau de bord) est une interface graphique Kubernetes officielle basée sur le web.

      Pour un aperçu conceptuel de Helm et de son écosystème de packaging, veuillez lire notre article, Une introduction à Helm.

      Conditions préalables

      Pour ce tutoriel, vous aurez besoin de :

      • Un cluster Kubernetes avec contrôle d’accès basé sur les rôles (RBAC) activé. Helm 3.1 prend en charge les clusters des versions 1.14 à 1.17. Pour plus d’informations, consultez la page des versions de Helm.
      • L’outil de ligne de commande kubectl installé sur votre machine locale, configuré pour vous connecter à votre cluster. Vous pouvez en savoir plus sur l’installation de kubectl dans la documentation officielle.

      Vous pouvez tester votre connectivité avec la commande suivante :

      Si vous ne voyez aucune erreur, vous êtes connecté au cluster. Si vous avez accès à plusieurs clusters avec kubectl, veillez à vérifier que vous avez choisi le contexte de cluster adéquat :

      • kubectl config get-contexts


      CURRENT NAME CLUSTER AUTHINFO NAMESPACE * do-fra1-helm3-example do-fra1-helm3-example do-fra1-helm3-example-admin

      Dans cet exemple, l’astérisque (*) indique que nous sommes connectés au cluster do-fra1-helm3-example. Pour changer les clusters exécutez :

      • kubectl config use-context context-name

      Lorsque vous êtes connecté au bon cluster, continuez à l’Étape 1 pour commencer à installer Helm.

      Étape 1 — Installation de Helm

      Tout d’abord, vous allez installer l’utilitaire de ligne de commande helm sur votre machine locale. Helm fournit un script qui gère le processus d’installation sur MacOS, Windows ou Linux.

      Entrez dans un répertoire inscriptible et téléchargez le script depuis le référentiel GitHub de Helm :

      • cd /tmp
      • curl -fsSL -o

      Rendez le script exécutable avec chmod :

      Vous pouvez utiliser votre éditeur de texte préféré pour ouvrir le script et l’inspecter, afin de vous assurer qu’il est sûr. Lorsque vous êtes satisfait, exécutez-le :

      Votre mot de passe peut vous être demandé. Saisissez-le et appuyez sur ENTER pour continuer.

      La sortie finale ressemblera à ceci :


      Downloading Preparing to install helm into /usr/local/bin helm installed into /usr/local/bin/helm

      Maintenant que vous avez installé Helm, vous êtes prêt à utiliser Helm pour installer votre premier tableau.

      Étape 2 — Installation d’un tableau Helm

      Les packages logiciels Helm sont appelés des tableaux. Il existe un référentiel de tableaux conservé, appelé stable, composé principalement de tableaux communs, que vous pouvez voir dans leur référentiel GitHub. Helm n’est pas préconfiguré pour cela, vous devrez donc l’ajouter manuellement. Ensuite, à titre d’exemple, vous allez installer le tableau de bord Kubernetes.

      Ajoutez le référentiel stable en exécutant :

      • helm repo add stable

      Le résultat sera :


      "stable" has been added to your repositories

      Ensuite, utilisez helm pour installer le package kubernetes-dashboard à partir du référentiel stable :

      • helm install dashboard-demo stable/kubernetes-dashboard --set rbac.clusterAdminRole=true

      Le paramètre --set vous permet de personnaliser les variables de tableaux, que le tableau affiche pour vous permettre de personnaliser sa configuration. Ici, vous définissez la variable d’application rbac.clusterAdminRole sur true pour donner l’accès à votre cluster entier au tableau de bord Kubernetes.

      La sortie ressemblera à :


      NAME: dashboard-demo LAST DEPLOYED: Tue Mar 31 15:04:19 2020 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: ...

      Notez la ligne NAME, surlignée dans l’exemple de sortie ci-dessus. Dans ce cas, vous avez spécifié le nom dashboard-demo. C’est le nom de la version. Une version Helm est un simple déploiement d’un tableau avec une configuration spécifique. Vous pouvez déployer plusieurs versions du même tableau, chacune ayant sa propre configuration.

      Vous pouvez énumérer toutes les versions dans le cluster :

      Le résultat sera similaire à celui-ci :


      NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION dashboard-demo default 1 2020-03-31 15:04:19.324774799 +0000 UTC deployed kubernetes-dashboard-1.10.1 1.10.1

      Vous pouvez maintenant utiliser kubectl pour vérifier qu’un nouveau service a été déployé sur le cluster :

      La sortie finale ressemblera à ceci :


      NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE dashboard-demo-kubernetes-dashboard ClusterIP <none> 443/TCP 4m44s kubernetes ClusterIP <none> 443/TCP 19m

      Notez que par défaut, le nom de service correspondant à la version est une combinaison du nom de la version Helm et du nom du tableau.

      Maintenant que vous avez déployé l’application, vous utiliserez Helm pour modifier sa configuration et mettre à jour le déploiement.

      Étape 3 — Mise à jour d’une version

      La commande helm upgrade peut être utilisée pour mettre à niveau une version avec un nouveau tableau ou un tableau mis à jour, ou pour mettre à jour ses options de configuration (variables).

      Vous allez apporter une simple modification à la version dashboard-demo pour démontrer le processus de mise à jour et de démantèlement : vous allez mettre à jour le nom du service du tableau de bord en kubernetes-dashboard, au lieu de dashboard-demo-kubernetes-dashboard.

      Le tableau kubernetes-dashboard fournit une option de configuration fullnameOverride pour contrôler le nom du service. Pour renommer la version, exécutez helm upgrade avec ce jeu d’options :

      • helm upgrade dashboard-demo stable/kubernetes-dashboard --set fullnameOverride="kubernetes-dashboard" --reuse-values

      En passant l’argument --reuse values, vous vous assurez que les variables de tableau que vous avez précédemment définies ne seront pas réinitialisées par le processus de mise à niveau.

      Vous verrez une sortie semblable à l’étape initiale d'installation de helm.

      Vérifiez si vos services Kubernetes reflètent les valeurs mises à jour :

      La sortie ressemblera à ce qui suit :


      NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP <none> 443/TCP 38m kubernetes-dashboard ClusterIP <none> 443/TCP 8s

      Notez que le nom du service a été mis à jour avec la nouvelle valeur.

      Remarque : à ce stade, vous pouvez charger le tableau de bord Kubernetes dans votre navigateur et le consulter. Pour ce faire, exécutez d’abord la commande suivante :

      Cela crée un proxy qui vous permet d’accéder aux ressources de cluster à distance depuis votre ordinateur local. En fonction des instructions précédentes, votre service de tableau de bord est nommé kubernetes-dashboard et il fonctionne dans le namespace par default. Vous pouvez maintenant accéder au tableau de bord grâce à l’URL suivante :


      Les instructions pour l’utilisation effective du tableau de bord sont hors sujet pour ce tutoriel, mais vous pouvez consulter les documents officiels du tableau de bord Kubernetes pour plus d’informations.

      Ensuite, vous verrez la capacité de Helm à revenir en arrière et à supprimer les versions.

      Étape 4 — Retour en arrière et suppression d’une version

      Lorsque vous avez mis à jour la version dashboard-demo à l’étape précédente, vous avez créé une deuxième révision de la version. Helm conserve tous les détails des versions précédentes si vous devez revenir sur une configuration ou un tableau précédents.

      Utilisez helm list pour inspecter à nouveau la version :

      Vous verrez la sortie suivante :


      NAME REVISION UPDATED STATUS CHART NAMESPACE dashboard-demo 2 Wed Aug 8 20:13:15 2018 DEPLOYED kubernetes-dashboard-0.7.1 default

      La colonne REVISION vous indique que c’est maintenant la deuxième révision.

      Utilisez helm rollback pour revenir à la première révision :

      • helm rollback dashboard-demo 1

      Vous devriez voir la sortie suivante, indiquant que le retour en arrière a réussi :


      Rollback was a success! Happy Helming!

      À ce stade, si vous lancez à nouveau kubectl get services, vous remarquerez que le nom du service est revenu à sa valeur précédente. Helm a re-deployé l’application avec la configuration de révision 1.

      Les versions Helm peuvent être supprimées avec la commande helm delete :

      • helm delete dashboard-demo

      Le résultat sera :


      release "dashboard-demo" uninstalled

      Vous pouvez essayer de lister les versions de Helm :

      Vous verrez qu’il n’y en a pas :



      Maintenant, la version a été réellement supprimée, et vous pouvez réutiliser le nom de la version.


      Dans ce tutoriel, vous avez installé l’outil de ligne de commande de helm et étudié l’installation, la mise à niveau, le retour en arrière et la suppression des tableaux de bord et des versions de Helm en gérant le tableau kubernetes-dashboard. 

      Pour plus d’informations sur Helm et les tableaux de Helm, veuillez consulter la documentation officielle de Helm.

      Source link