Installing and Removing Software

Installing needs root

Installing software changes the whole system, so it needs administrator rights. Try it as yourself and you're refused; with sudo it works. (Your password is student.) Install jq, a tool for reading JSON:

apk add jq

In the terminal

student@vulntech:~$ apk add jq
ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

That failed: a normal user may not change the system. Now with sudo:

sudo apk add jq

In the terminal

student@vulntech:~$ sudo apk add jq
[sudo] password for student:
(1/2) Installing oniguruma (6.9.9-r0)
  0%                                                                            21% ███████████████                                                            42% ███████████████████████████████                                           (2/2) Installing jq (1.7.1-r0)
 43% ████████████████████████████████                                           64% ███████████████████████████████████████████████                            71% █████████████████████████████████████████████████████                      93% ████████████████████████████████████████████████████████████████████      100% ██████████████████████████████████████████████████████████████████████████Executing busybox-1.37.0-r14.trigger
OK: 108 MiB in 130 packages

Notice it installed two packages: jq and the library it depends on. The package manager pulled the dependency in without being asked. Now jq works:

echo '{"ship":"Pearl","crew":12}' | jq .crew

In the terminal

student@vulntech:~$ echo '{"ship":"Pearl","crew":12}' | jq .crew
12

What did it install? apk info -L

Now that jq is installed, apk info -L lists the files it put on the system:

apk info -L jq

In the terminal

student@vulntech:~$ apk info -L jq
jq-1.7.1-r0 contains:
usr/bin/jq
usr/lib/libjq.so.1
usr/lib/libjq.so.1.0.4

Installing several at once

Name as many packages as you like. Here are two small toys, figlet (big letters) and sl:

sudo apk add figlet sl
figlet Ahoy

In the terminal

student@vulntech:~$ sudo apk add figlet sl
[sudo] password for student:
(1/2) Installing figlet (2.2.5-r3)
  0%                                                                             3% ██                                                                         11% ████████                                                                   12% █████████                                                                  14% ██████████                                                                 15% ███████████                                                                16% ████████████                                                               17% █████████████                                                              18% ██████████████                                                             20% ██████████████                                                             21% ███████████████                                                            22% ████████████████                                                           23% █████████████████                                                          25% ██████████████████                                                         26% ███████████████████                                                        27% ████████████████████                                                       28% █████████████████████                                                      29% ██████████████████████                                                     31% ███████████████████████                                                    32% ███████████████████████                                                    33% ████████████████████████                                                   34% █████████████████████████                                                  36% ██████████████████████████                                                 37% ███████████████████████████                                                38% ████████████████████████████                                               39% █████████████████████████████                                              41% ██████████████████████████████                                             43% ████████████████████████████████                                           45% █████████████████████████████████                                          47% ██████████████████████████████████                                         48% ████████████████████████████████████                                       50% █████████████████████████████████████                                      52% ██████████████████████████████████████                                     57% ██████████████████████████████████████████                                 61% █████████████████████████████████████████████                              65% ████████████████████████████████████████████████                           68% ██████████████████████████████████████████████████                         70% ████████████████████████████████████████████████████                       71% ████████████████████████████████████████████████████                       72% █████████████████████████████████████████████████████                      74% ███████████████████████████████████████████████████████                    75% ████████████████████████████████████████████████████████                   76% ████████████████████████████████████████████████████████                   80% ███████████████████████████████████████████████████████████                82% █████████████████████████████████████████████████████████████              95% ██████████████████████████████████████████████████████████████████████     96% ███████████████████████████████████████████████████████████████████████    97% ████████████████████████████████████████████████████████████████████████  (2/2) Installing sl (5.02-r1)
 97% ████████████████████████████████████████████████████████████████████████  100% ██████████████████████████████████████████████████████████████████████████Executing busybox-1.37.0-r14.trigger
OK: 108 MiB in 130 packages
student@vulntech:~$ figlet Ahoy
    _    _
   / \  | |__   ___  _   _
  / _ \ | '_ \ / _ \| | | |
 / ___ \| | | | (_) | |_| |
/_/   \_\_| |_|\___/ \__, |
                     |___/

Removing: apk del

apk del removes a package. Like installing, it needs sudo:

sudo apk del jq
jq --version

In the terminal (jq is gone, so the last command fails)

student@vulntech:~$ sudo apk del jq
[sudo] password for student:
(1/2) Purging jq (1.7.1-r0)
  0%                                                                           (2/2) Purging oniguruma (6.9.9-r0)
 50% █████████████████████████████████████                                     100% ██████████████████████████████████████████████████████████████████████████Executing busybox-1.37.0-r14.trigger
OK: 107 MiB in 128 packages
student@vulntech:~$ jq --version
-bash: jq: command not found

Removing jq also removed the library that had been pulled in only for it: the package manager cleans up dependencies that nothing else needs.

Is it installed? apk info -e

apk info -e NAME prints the name if the package is installed and nothing if it isn't, which is perfect for a script:

sudo apk add bc >/dev/null
apk info -e bc
apk info -e nosuchpackage
echo done

In the terminal

student@vulntech:~$ sudo apk add bc >/dev/null
[sudo] password for student:
student@vulntech:~$ apk info -e bc
bc
student@vulntech:~$ apk info -e nosuchpackage
student@vulntech:~$ echo done
done

Common mistake: apk add and apk del both need sudo. apk search and apk info don't: reading the catalogue changes nothing, so any user can do it.

Remember: sudo apk add NAME installs (with its dependencies), sudo apk del NAME removes (cleaning up unused dependencies). apk info -L lists an installed package's files.

HOME LEARN COMMUNITY DASHBOARD
Practice terminal Starting…