Ubuntu Package Management: Difference between revisions

From CompleteNoobs
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 84: Line 84:
===== '''dpkg''' remove=====
===== '''dpkg''' remove=====


<code>dpkg -l | grep steam</core>
<code>dpkg -l | grep steam</code>
* returns/output
* returns/output
<pre>
<pre>
Line 91: Line 91:
</pre>
</pre>


<code>apt remove steam:i386</core>
<code>apt remove steam:i386</code>
* return output
* return output
<pre>Package 'steam:i386' is not installed, so not removed</core>
<pre>Package 'steam:i386' is not installed, so not removed</pre>


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.
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.

Latest revision as of 11:51, 3 May 2023

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