Wednesday 24 April 2024

Installing Software on Linux

 


How to install software available in Package Repository?

Installing from Ubuntu Package Repository

Example: Installing VLC player

$ sudo apt-get update
$ sudo apt-get install vlc

It's best to run sudo apt-get update first as this updates local information about what packages are available from where in what versions. This can prevent a variety of installation errors (including some "unmet dependencies" errors), and also ensures you get the latest version provided by your enabled software sources.

There is also an apt version of this command:

sudo apt update
...
Reading package lists... Done
Building dependency tree       
Reading state information... Done
23 packages can be upgraded. Run 'apt list --upgradable' to see them.
...

To list all upgradable packages:

sudo apt list --upgradable

To upgrade all packages:

$ sudo apt upgrade

To see all installed packages:

$ sudo apt list --installed

To check if some package has already been installed:

$ sudo apt list --installed | grep package_name

...

If using Alpine distribution, you need to use apkComparison with other distros - Alpine Linux


Installing from non-default (3rd Party) Package Repository


Example: Installing PowerShell from Microsoft Package Repository

# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Enable the "universe" repositories
sudo add-apt-repository universe

# Install PowerShell
sudo apt-get install -y powershell

# Start PowerShell
pwsh


If you install the wrong version of packages-microsoft-prod.deb you can uninstall it with:

sudo dpkg -r packages-microsoft-prod
(Reading database ... 254902 files and directories currently installed.)
Removing packages-microsoft-prod (1.0-3) ...


How to install software distributed via Debian package (.deb) files?  

Some applications are not available in Debian Package Repository but can be downloaded as .deb files.

$ sudo dpkg -i /path/to/deb/file 
$ sudo apt-get install -f

The latter is necessary in order to fix broken packages (install eventual missing/unmet dependencies).

How to install a deb file, by dpkg -i or by apt?

Another example: Etcher

Debian and Ubuntu based Package Repository (GNU/Linux x86/x64)

Add Etcher debian repository:

echo "deb https://deb.etcher.io stable etcher" | sudo tee /etc/apt/sources.list.d/balena-etcher.list

Trust Bintray.com's GPG key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 379CE192D401AB61

Update and install:

sudo apt-get update
sudo apt-get install balena-etcher-electron

Uninstall

sudo apt-get remove balena-etcher-electron
sudo rm /etc/apt/sources.list.d/balena-etcher.list
sudo apt-get update


How to install applications distributed via snaps?

Snaps are containerised software packages. They're designed to install the programs within them on all major Linux systems without modification. Snaps do this by developers bundling a program's latest libraries in the containerized app.

Snap updates automatically and carries all its library dependencies, so is a better choice for users who want ease of deployment and to stay on top of the latest developments.

Snapcraft - Snaps are universal Linux packages

Installing snap on Ubuntu | Snapcraft documentation

How to Install and Use Snap on Ubuntu 18.04 - codeburst



Installing binaries


Some applications are distributed as binary files. We need to download them and set executable permissions. Instead of using cp and chmod commands, we can use install command which copies file to destination directory and automatically sets -rwxr-xr-x permissions over the file:

$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

$ sudo install minikube-linux-amd64 /usr/local/bin/minikube

$ ls -la /usr/local/bin/minikube
-rwxr-xr-x 1 root root 95637096 Apr 24 01:01 /usr/local/bin/minikube



We can pass to install command flags to set the owner and the group and also permission mode (as in chmod), instead of rwxr-xr-x:

$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

0755 permissions mean the following: user can 7=read(4)+write(2)+execute(1); group can 5=read(4)+execute(1); anyone/world can 5=read(4)+execute(1) 

If you do not have root access on the target system, you can still install kubectl to the ~/.local/bin directory:

chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl
# and then append (or prepend) ~/.local/bin to $PATH


It's worth noting here that install command can also just create a directory (all components of the path, like mkdir -p) and specify permissions on it:

$ install -m 0755 -d /etc/apt/keyrings


---

No comments: