Ubuntu Package Management

From CompleteNoobs
Jump to navigation Jump to search
Please Select a Licence from the LICENCE_HEADERS page
And place at top of your page
If no Licence is Selected/Appended, Default will be CC0

Default Licence IF there is no Licence placed below this notice! When you edit this page, you agree to release your contribution under the CC0 Licence

LICENCE: More information about the cc0 licence can be found here:
https://creativecommons.org/share-your-work/public-domain/cc0

The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Licence:

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:

   the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
   moral rights retained by the original author(s) and/or performer(s);
   publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
   rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
   rights protecting the extraction, dissemination, use and reuse of data in a Work;
   database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
   other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.

4. Limitations and Disclaimers.

   No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
   Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
   Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
   Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

A package management system, also known as a package manager, is a set of tools and processes that automate the installation, upgrading, configuration, and removal of software packages on a computer system. Package management systems simplify the process of managing software by handling package dependencies, versioning, and distribution in a consistent and organized manner.

In the context of operating systems like Linux and Unix, software packages are bundles of files, libraries, executables, and metadata that together comprise a complete application or software component. Package managers are designed to manage these packages by tracking and resolving their dependencies, which are other software components that a package requires to function properly.

Key functions of package management systems include:

  • Maintaining repositories: Package managers connect to repositories, which are remote servers that store packages and their metadata. Repositories provide a centralized location for users to find, download, and install software packages.
  • Managing dependencies: When installing or upgrading a package, the package manager ensures that all required dependencies are also installed, updated, or removed as necessary. This helps maintain system stability and prevents conflicts or broken software.
  • Versioning: Package managers track and manage different versions of software packages, allowing users to install, upgrade, or downgrade specific versions as needed.
  • Handling package conflicts: Package managers can detect and resolve conflicts between packages, ensuring that the system remains in a consistent state even when multiple packages have overlapping or conflicting requirements.
  • Streamlining software installation and removal: Package managers automate the process of installing, upgrading, or removing software, making it easy for users to manage software on their systems without manual intervention.

Popular package managers include APT (used in Debian-based distributions), YUM and DNF (used in Red Hat-based distributions), and pacman (used in Arch Linux-based distributions). Each package manager is designed to work with specific package formats (such as .deb or .rpm) and may have its unique commands and features, but their overall purpose remains the same: to simplify and automate the process of managing software on a computer system.

Package managers

Ubuntu is a popular Linux-based operating system that offers a wide range of applications for users. To install these applications, Ubuntu provides several package managers such as APT, Snap, AppImage, and Flatpak. Each package manager has its own advantages and disadvantages, and it's important to understand how they work and what they offer in order to choose the best one for your needs.

APT (Advanced Package Tool) is the default package manager for Ubuntu, and it uses a command-line interface to manage packages. APT offers a large selection of packages, and it's designed to be stable and reliable. Snap, on the other hand, is a newer package manager that offers a more user-friendly interface and sandboxed apps. It also offers automatic updates and rollbacks, making it easy to manage and maintain applications.

AppImage and Flatpak are containerized formats that allow applications to run on multiple Linux distributions without needing to install dependencies. AppImage is a self-contained format that includes all dependencies, making it easy to run on any Linux distribution without needing to install anything. Flatpak, on the other hand, allows for more fine-grained control over dependencies and offers sandboxing and automatic updates.

By understanding the differences between these package managers, you can choose the best one for your needs and enjoy a wide range of applications on Ubuntu.

Installing and updating software

APT

Update the package index:

Before installing or updating software, it's essential to update the package index to ensure you have the latest information about available packages and their versions. Run the following command:

sudo apt update

This command will download package information from your configured repositories and update the local package index.

Search APT for packages

To search for packages in the Ubuntu repository using APT, you can use the apt-cache search command followed by a keyword. For example:

sudo apt-cache search <package-name>

Replace <package-name> with the name or keyword related to the package you are looking for.

Once you have found the package you want to install, you can install it using the apt-get install or apt install command.

Install a new package:

To install a new package, use the apt install command followed by the package name:

sudo apt install <package-name>

Replace <package-name> with the name of the package you want to install. APT will automatically handle the package's dependencies, installing them if necessary.

Update installed packages:

To update all the installed packages to their latest available versions, run:

sudo apt upgrade

This command will upgrade packages based on the updated package index. It's a good practice to run this command regularly to keep your system up to date and secure.

Update a specific package:

If you want to update a specific package, use the apt install command again:

sudo apt install --only-upgrade <package-name>

Replace <package-name> with the name of the package you want to update. This command will only upgrade the specified package if a newer version is available.

Remove a package:

If you want to remove a package, use the apt remove command followed by the package name:

sudo apt remove <package-name>

Replace <package-name> with the name of the package you want to remove. Note that this command does not remove the package's configuration files. If you want to remove the package along with its configuration files, use the apt purge command instead:

sudo apt purge <package-name>

dpkg remove

dpkg -l | grep steam

  • returns/output
rc  steam:i386                                    1:1.0.0.74-1ubuntu2                        i386         Valve's Steam digital software delivery system
rc  steam-launcher                                1:1.0.0.76                                 all          Launcher for the Steam software distribution service

apt remove steam:i386

  • return output
Package 'steam:i386' is not installed, so not removed

The dpkg -l | grep steam command shows that the steam:i386 and steam-launcher packages are installed on your system, but when you try to remove them using the apt remove command, you get a message that the packages are not installed.

This can happen if the packages were installed manually using a different method than the standard apt package manager. In this case, the packages were likely installed manually by downloading and installing the Steam installer from the Steam website.

To remove the Steam packages that are installed manually, you can run the following commands:

sudo dpkg -r steam:i386

sudo dpkg -r steam-launcher

Use --purge to remove config files

sudo dpkg --purge steam:i386

Clean up unused dependencies:

Over time, your system may accumulate unused dependency packages. You can clean up these packages using the apt autoremove command:

sudo apt autoremove

This command will remove any packages that were installed as dependencies but are no longer needed by any installed software.

Install from a .deb file

To install a .deb file that you have downloaded or obtained from an external source, you can use the dpkg command. First, navigate to the directory containing the .deb file using the cd command:

cd /path/to/directory

Then, install the .deb file using the dpkg -i command:

sudo dpkg -i <filename.deb>

Replace <filename.deb> with the exact name of the .deb file you want to install.

Note that you can also use path if you do not want to cd:sudo dpkg -i /path/to/program.deb

Note that if the .deb package has any unmet dependencies, the installation may fail. To resolve this issue and automatically install any missing dependencies, you can run the following command:

sudo apt-get install -f

or

sudo apt install -f

This will install any missing dependencies and complete the installation of the .deb package.

Managing Package Repositories

  • Introduction to Package Repositories
Package repositories are online servers that store software packages for installation and updates on Ubuntu systems. Ubuntu uses the Advanced Package Tool (APT) to manage these repositories. The default repositories include Main, Universe, Restricted, and Multiverse. You can also add third-party repositories (PPAs) for additional software.

Default Repositories

  • Main: Officially supported, open-source software maintained by Canonical.
  • Universe: Community-maintained open-source software.
  • Restricted: Proprietary drivers and software required for hardware compatibility.
  • Multiverse: Software not compliant with the Ubuntu licensing policies.
  • Updating Package List
Before installing new packages, you should update the package list to fetch the latest information from the repositories.
  • Open a terminal (Ctrl+Alt+T)
  • Run the following command:

sudo apt update

Adding a Personal Package Archive (PPA)
PPAs are third-party repositories that contain software not available in the default repositories.
  • To add a PPA, open a terminal and type:

sudo add-apt-repository ppa:user/ppa-name

Replace "user" and "ppa-name" with the appropriate values.

Update the package list:

sudo apt update

Removing a PPA

  • To remove a PPA, open a terminal and type:

sudo add-apt-repository --remove ppa:user/ppa-name

Replace "user" and "ppa-name" with the appropriate values.

Update the package list:

sudo apt update

Example: Finding the ppa:user/ppa-name to remove:

  • when i try an apt update
 The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F24AEA9FB05498B7
Reading package lists... Done
W: GPG error: https://repo.steampowered.com/steam stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F24AEA9FB05498B7
E: The repository 'https://repo.steampowered.com/steam stable InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
  • Finding the package's and the repository
Check which packages are installed from the repository with the following command:

dpkg --list | grep steam

Remove any packages that are installed from the repository with the following command:

sudo apt-get remove --purge <package-name>

Find repository's

ls -l /etc/apt/sources.list.d/

  • Returns:
-rw-r--r-- 1 root root 296 Mar  1 18:55 steam-beta.list
-rw-r--r-- 1 root root 228 Mar  1 18:55 steam-stable.list

cat /etc/apt/sources.list.d/steam-stable.list

  • returns:
deb [arch=amd64,i386 signed-by=/usr/share/keyrings/steam.gpg] https://repo.steampowered.com/steam/ stable steam
deb-src [arch=amd64,i386 signed-by=/usr/share/keyrings/steam.gpg] https://repo.steampowered.com/steam/ stable steam

cat /etc/apt/sources.list.d/steam-beta.list

  • returns:
# Uncomment these lines to try the beta version of the Steam launcher
#deb [arch=amd64,i386 signed-by=/usr/share/keyrings/steam.gpg] https://repo.steampowered.com/steam/ beta steam
#deb-src [arch=amd64,i386 signed-by=/usr/share/keyrings/steam.gpg] https://repo.steampowered.com/steam/ beta steam
  • Note: In steam-beta.list the lines are commented out with # at the beginning of the line.
  • You can comment out the lines in steam-stable.list and sudo apt update
  • Or you can delete the file steam-stable.list and sudo apt update

Editing Repository Configuration Files

The repository configuration files are stored in the /etc/apt/sources.list file and the files inside /etc/apt/sources.list.d/ directory.

  • To edit the sources.list file, open a terminal and type:

sudo nano /etc/apt/sources.list

Make the necessary changes, save (Ctrl+O), and exit (Ctrl+X). Update the package list:

sudo apt update

Managing Repositories with Software & Updates

  • You can also manage repositories using the Software & Updates application.
  • Open the application by searching "Software & Updates" in the applications menu.
  • In the "Ubuntu Software" tab, you can enable or disable the default repositories.
  • In the "Other Software" tab, you can add, edit, or remove third-party repositories.
  • After making changes, click "Close" and then click "Reload" to update the package list.

By following this tutorial, you'll be able to manage package repositories on your Ubuntu system, adding or removing PPAs as needed to install or update software.


Dependency Management

In Ubuntu, software packages often rely on other packages to function properly. These required packages are called dependencies. The Advanced Package Tool (APT) automatically handles dependency management, ensuring that all required packages are installed or updated when you install, update, or remove a package.

Installing a Package and Its Dependencies
When you install a package using APT, it automatically resolves and installs the dependencies.
  • Open a terminal (Ctrl+Alt+T)
  • Install a package and its dependencies using the following command:

sudo apt install package-name

Replace "package-name" with the appropriate package name.
  • Updating Packages and Dependencies
APT also manages the dependencies while updating packages.
  • To update all installed packages and their dependencies, run the following command:

sudo apt update && sudo apt upgrade

Removing a Package and Unused Dependencies
When you remove a package, APT will not automatically remove its dependencies if they are no longer required. To remove unused dependencies, use the 'autoremove' command.
  • To remove a package and its unused dependencies, run:

sudo apt remove package-name && sudo apt autoremove

  • Replace "package-name" with the appropriate package name.
  • Fixing Broken Dependencies
Sometimes, you may encounter broken dependencies due to various reasons, such as interrupted installations or package conflicts. You can use APT to fix these issues.
  • To fix broken dependencies, run the following commands:
    sudo apt update
    sudo apt install -f
Listing Dependencies of a Package
You can use the apt-cache command to list the dependencies of a specific package without installing it.
  • To list the dependencies, run:

apt-cache depends package-name

  • Replace "package-name" with the appropriate package name.
Listing Reverse Dependencies
Reverse dependencies are packages that depend on a specific package. You can list them using the 'apt-cache' command.
  • To list reverse dependencies, run:

apt-cache rdepends package-name

Replace "package-name" with the appropriate package name.

Create a deb package

Create deb repository

Snaps

Ubuntu Snap packages are a universal packaging format designed to work across different Linux distributions. Snap packages are self-contained and automatically updated, which makes them a convenient choice for both sysadmins and new users. Here's an in-depth guide to help you understand and use Snap packages in Ubuntu:

Installation of Snapd:

Before you can manage Snap packages, you need to have the snapd service installed on your Ubuntu system. It usually comes pre-installed on recent versions of Ubuntu.

Check snapd is installed on your system with:
snap --version

However, if it's not installed, you can install it using the following command:

sudo apt update
sudo apt install snapd

Searching for Snap packages:

To search for available Snap packages, use the snap find command followed by a keyword:

snap find <keyword>

Replace <keyword> with the name or keyword related to the package you are looking for.

Installing Snap packages:

To install a Snap package, use the snap install command:

sudo snap install <snap-package-name>

Replace <snap-package-name> with the exact name of the Snap package you want to install.

Listing installed Snap packages:

To see a list of installed Snap packages on your system, use the snap list command:

snap list

Updating Snap packages

Snap packages are updated automatically by default. However, if you want to manually update a specific Snap package, you can use the snap refresh command:

sudo snap refresh <snap-package-name>

To update all Snap packages on your system, simply run:

sudo snap refresh

Removing Snap packages

To remove an installed Snap package, use the snap remove command:

sudo snap remove <snap-package-name>

Replace <snap-package-name> with the exact name of the Snap package you want to remove.

Removing Snap and also delete the package's data and configuration files

snap remove --purge example_package

The --purge option is used to specify that you not only want to remove the snap package, but also to delete its associated data and configuration files. This option helps ensure that all remnants of the package are removed from your system, providing a clean uninstall.

Managing Snap package services

Some Snap packages provide system services. You can manage these services using the snap services command:

snap services

This will list all services provided by installed Snap packages.

To start, stop, restart, or check the status of a Snap service, use the following commands:

sudo snap start <snap-package-name>
sudo snap stop <snap-package-name>
sudo snap restart <snap-package-name>
sudo snap status <snap-package-name>

Replace <snap-package-name> with the exact name of the Snap package containing the service you want to manage.

Snap package channels

Snap packages are distributed through different channels, such as stable, candidate, beta, and edge. By default, the stable channel is used. To install a Snap package from a specific channel, use the --channel option:

sudo snap install <snap-package-name> --channel=<channel-name>

Replace <snap-package-name> with the name of the Snap package and <channel-name> with the desired channel (e.g., stable, candidate, beta, or edge).

For more information and advanced options, you can refer to the official Snapcraft documentation: https://snapcraft.io/docs

Create a snap package

AppImage

Flatpak