package managers | service managers
brew | apt | yum | apk | choco | |
---|---|---|---|---|---|
operating system | Mac OS X | Debian, Ubuntu | Fedora, CentOS | Alpine | Windows |
show version | $ brew --version $ brew config |
$ apt --version | PS> choco --version | ||
queries | |||||
brew | apt | yum | apk | windows | |
list commands | $ brew help $ man brew |
$ apt help | $ yum help | $ apk help | PS> choco -? |
describe command foo | $ brew help foo | $ yum help foo | $ apk //foo// --help | PS> choco //foo// --help | |
describe package foo | $ brew info foo | $ apt show foo | $ apk info foo | PS> choco info foo | |
list files in installed package foo | $ brew list foo | $ dpkg-query -L foo | $ repoquery -l foo | ||
find package (not necessarily installed) with foo.h | $ sudo apt-get install -y apt-file $ apt-file update $ apt-file search foo.h |
$ yum provides foo.h | |||
search available packages for foo | $ brew search foo | $ apt search foo | $ yum search foo | $ apk search foo | PS> choco list foo |
show required dependencies for foo | $ brew deps foo | $ apt-cache depends foo | |||
show packages depending on foo | $ brew uses --installed foo $ brew uses foo |
$ apt-cache rdepends foo | |||
number of available packages | $ brew search | wc -l 4925 |
$ apt search ' ' \ | grep -E '^[^ ]' \ | wc -l 165452 |
$ yum list | wc -l 3787 |
PS> choco list -a | measure-object -line 5046 |
|
list installed packages | $ brew list | $ dpkg -l | $ yum list installed | $ apk info | PS> choco list --local-only |
show installed package versions | $ brew list --versions | $ dpkg -l | PS> choco list --local-only | ||
diagnostics | $ brew doctor | $ sudo apt-get check | |||
updates | |||||
brew | apt | yum | apk | windows | |
install package foo | $ brew install foo | $ sudo apt-get install -y foo | $ sudo yum install -y foo | $ apk add foo | PS> choco install -y foo |
install package foo from file | $ brew install -d foo.rb | $ sudo dpkg -i foo.deb | $ sudo yum localinstall foo.rpm | ||
remove package foo | $ brew uninstall foo remove all installed versions: $ bew uninstall --force foo |
$ sudo apt remove foo | $ sudo yum erase foo | $ apk del foo | PS> choco uninstall foo |
update list of available packages | $ brew update | $ sudo apt update | $ apk update | does not store list locally | |
upgrade package | $ brew upgrade foo | $ apk add -u foo | |||
remove local old version of package | $ brew cleanup foo | ||||
switch to old local version of package | $ brew switch foo version | ||||
upgrade all installed packages to up-to-date versions | $ brew upgrade | $ sudo apt upgrade | |||
prevent package from being upgraded when upgrading all packages | $ brew pin foo | ||||
show out-of-date packages | $ brew outdated | $ apt-get --dry-run upgrade | |||
custom repos | |||||
brew | apt | yum | apk | windows | |
list repos (default and added) | $ brew tap | $ grep -v '^#'^Cetc/apt/sources.list | $ cat /etc/yum.repos.d/*.rep | ||
add repo | $ brew tap dart-lang/dart | $ sudo apt edit-sources | $ yum --enablerepo rpmforge \ install foo |
||
remove repo | $ brew untap dart-lang/dart | ||||
add trusted key | $ curl -L http://foo.com/repo_key \ | sudo apt-key add - |
||||
package format | |||||
brew | apt | yum | apk | windows | |
package suffix | .rb | .deb | .rpm | .apk | |
package format | $ ar -r foo.deb debian-binary \ control.tar.gz data.tar.gz |
$ cat \ control.tar.gz \ data.tar.gz \ > foo-1.0.apk |
|||
list package contents | $ brew list foo | $ ar -t foo.deb | |||
extract file from package | $ ar -x foo.deb control.tar.gz | ||||
____________________________ | _______________________________________ | _______________________________________ | _______________________________________ | ____________________________________ | _________________________________________________ |
Service Managers
launchd (Mac) | systemd (Linux) | upstart (Ubuntu) | |
---|---|---|---|
daemon name | launchd | init | init |
startup directories | /System/Library/LaunchDaemons /System/Library/LaunchAgents /Library/LaunchDaemons /Library/LaunchAgents ~/Library/LaunchAgents |
/lib/systemd/system | /etc/init /etc/init.d ~/.init |
startup file format | XML property list; see man launchd.plist | an INI style config file; see: $ man systemd.unit |
format of files in /etc/init is described by man 5 init. The files in /etc/init.d are executables supporting standard service subcommands. |
current runlevel | $ who -r | $ who -r | $ runlevel $ who -r |
manage services | |||
show services | $ launchctl list | $ systemctl list-units | $ initctl list |
describe service | $ launchctl list SERVICE | $ systemctl show ntp | |
service status | $ systemctl status ntp | $ initctl status ssh $ status ssh |
|
stop service | $ systemctl stop ntp | $ service SERVICE stop $ /etc/init.d/SERVICE stop |
|
start service | $ systemctl start ntp | $ service SERVICE start $ /etc/init.d/SERVICE start |
|
restart service | $ systemctl restart ntp | $ service SERVICE restart $ /etc/init.d/SERVICE restart |
|
____________________________ | _____________________________________ | _____________________________________ | _____________________________________ |
TODO
- automatic (apt)
- brew services
Package Managers
brew
brew is intended to be run as a non-privileged user. This is achieved by making /usr/local owned and writable by that non-privileged user.
{{brew}} installs the files for a package in {{/usr/local/Cellar/PACKAGE/VERSION}}. This path, including the package name and the version, is called a keg. {{brew}} creates symlinks in {{/usr/local/{bin,etc,include,lib,man,opt,share} pointing to files in /usr/local/Cellar.
A brew formula is a ruby file defining a subclass of Formula. The subclass defines a url attribute, which is the url of the tarball to be downloaded, and an install method, which is a script which performs the installation.
Brew formulas are kept in a git repository called a tap. brew makes a shallow git clone of each tapped repository in /usr/local/Homebrew/Library/Taps.
The formulas for the homebrew/core tap can be studied at https://github.com/Homebrew/homebrew-core/tree/master/Formula.
brew cask
brew cask is an extension for brew which is used to add macOS apps.
$ brew tap caskroom/cask
$ brew cask search chrome
$ brew cask install google-chrome
$ brew cask info google-chrome
$ brew cask upgrade google-chrome
$ brew cask uninstall google-chrome
brew services
apt
yum
apk
Alpine Linux package management
choco
To install choco, run the PowerShell as administrator and execute these commands:
PS> set-executionpolicy bypass
PS> iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco commands that modify the system (i.e. install or uninstall packages) must be run inside a PowerShell with administrative privilege.
Service Managers
A service manager is responsible for starting services when a system is booted.
In early versions of Unix (Research Unix and BSD), the init process ran shell scripts to initialize the system. The most important script was /etc/rc, but there was also /etc/rc.conf and the directory /etc/rc.d.
With System III and System V, instead of running a shell script, the init process read the /etc/inittab configuration file, which had lines in this format:
id:runlevels:action:process
Run levels determined which services would run. Typically the available run levels were:
0 | shutdown |
1 | single user mode |
2-4 | multi-user mode |
5 | X windows |
6 | reboot |
To get the current run level:
$ who -r
The actions for each service (start, stop, and restart) were defined by a script in /etc/init.d with a format like this:
case "$1" in
start)
echo "starting"
;;
stop)
echo "stopping"
;;
restart)
echo "restarting"
;;
*)
echo "USAGE: start|stop|restart"
;;
esac
It was also possible to invoke these actions with the service command:
$ sudo service ssh stop
launchd
systemd
upstart
14.10 was the last version of Ubuntu to use Upstart as the init daemon.
windows services
How to: Create Windows Services
To start a program at login, put a shortcut to it in the Startup folder. To open the Startup folder, type Cmd+R and then shell:startup.
The Task Scheduler can run a program at login or at a scheduled time. Search for Schedule tasks to launch it. Then Action | Create Basic Task... At the end of the task creation, one can check the "Open properties dialog..." checkbox. This exposes all the settings available to shortcuts, including the ability to run the task with administrator privilege, which is something that cannot be done by dropping a shortcut into the Startup folder.