Ubuntu Install Cheatsheet
Common install and cleanup commands for Ubuntu, kept around for copy-paste.
~/posts/ubuntu-install-guide $ cat post.md
Add swap on a low-memory machine
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl vm.vfs_cache_pressure=50
echo 'vm.vfs_cache_pressure=50' | sudo tee -a /etc/sysctl.conf
Theme
sudo add-apt-repository ppa:noobslab/themes
sudo apt-get update
sudo apt-get install flatabulous-theme
sudo add-apt-repository ppa:noobslab/icons
sudo apt-get update
sudo apt-get install ultra-flat-icons
DigitalOcean agent
curl -sSL https://agent.digitalocean.com/install.sh | sh
G++
sudo apt-get install g++
Steam / NVIDIA drivers
The modern way to install NVIDIA drivers on Ubuntu 14.04+:
Add the graphics-drivers PPA:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
Install the recommended driver:
sudo ubuntu-drivers autoinstall
Reboot:
sudo reboot
If that doesn’t work, or you want to pick a specific driver:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
Purge anything nvidia-related already installed:
sudo apt-get purge nvidia\*
Check which drivers are available:
ubuntu-drivers devices
Install one:
sudo apt-get install nvidia-361
Reboot:
sudo reboot
Chrome
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install google-chrome-stable
Ubuntu Tweak
wget -q -O - http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -
sudo sh -c 'echo "deb http://archive.getdeb.net/ubuntu xenial-getdeb apps" >> /etc/apt/sources.list.d/getdeb.list'
sudo apt-get update
sudo apt-get install ubuntu-tweak
UMake
sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
VS Code (via UMake)
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make
sudo apt-get update
sudo apt-get install ubuntu-make
umake web visual-studio-code
VS Code (via apt)
VS Code enabled official Linux repositories in February 2017 (v1.10):
sudo add-apt-repository -y "deb https://packages.microsoft.com/repos/vscode stable main"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EB3E94ADBE1229CF
sudo apt update
sudo apt -y install code
Upgrade / dist-upgrade as usual:
sudo apt -y upgrade
sudo apt -y dist-upgrade
Fonts
sudo mkdir -p /usr/share/fonts/consolas
sudo cp YaHei.Consolas.1.12.ttf /usr/share/fonts/consolas/
sudo chmod 644 /usr/share/fonts/consolas/YaHei.Consolas.1.12.ttf
cd /usr/share/fonts/consolas
sudo mkfontscale && sudo mkfontdir && sudo fc-cache -fv
NodeJS
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
sudo apt-get install -y nodejs
Git
apt-get install git
sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
Python
sudo apt-get install python-pip
Cleanup
1. Remove leftover config files
Two commands for removing a package on Debian/Ubuntu:
sudo apt-get remove <package-name>
sudo apt-get purge <package-name>
remove deletes the package but keeps its config; purge deletes the
config too.
Find packages that still have leftover config:
dpkg --list | grep "^rc"
rc in the first column means the package is Removed but Config-file
remains. Extract the names:
dpkg --list | grep "^rc" | cut -d " " -f 3
Delete them:
dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge
You’ll see something like:
(Reading database ... 64538 files and directories currently installed.)
Removing libapt-inst1.4:amd64 (0.8.16~exp12ubuntu10.11) ...
Purging configuration files for libapt-inst1.4:amd64 (0.8.16~exp12ubuntu10.11) ...
Removing libbind9-80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
Purging configuration files for libbind9-80 (1:9.8.1.dfsg.P1-4ubuntu0.6) ...
To purge only one package’s config:
sudo dpkg --purge <package-name>
2. Remove unneeded .deb cache
apt-get install keeps downloaded .deb archives in
/var/cache/apt/archives. If you install often, they add up. Check
the size:
du -sh /var/cache/apt/archives
Clean them:
sudo apt-get clean
sudo apt-get autoclean
3. Remove orphan packages
apt-get pulls in dependencies automatically. Removing the top-level
package leaves those dependencies behind — orphans:
sudo apt-get autoremove
apt-get autoremove only deletes things apt-get itself installed as
dependencies. For manually-installed orphans, use deborphan:
sudo apt-get install deborphan
List orphans:
deborphan
Delete them:
deborphan | xargs sudo apt-get purge -y
4. Remove obsolete packages
“Obsolete” means none of the repositories in /etc/apt/sources.list
provides this package’s .deb anymore — possibly because upstream is
gone, the user base shrank, or the package was renamed. These won’t
receive security updates and can break upgrades, so it’s worth
clearing them.
Find them:
sudo aptitude search ?obsolete
Example output:
i linux-image-3.2.0-29-generic - Linux kernel image for version 3.2.0 on 64
Delete it:
sudo apt-get purge linux-image-3.2.0-29-generic
Or purge all obsolete packages at once:
sudo aptitude purge ~o
Note: some packages that aren’t in any repo aren’t actually obsolete —
e.g. a .deb you downloaded manually like ubuntu-tweak. aptitude purge ~o would catch those too. Prefer hand-picking with apt-get purge.
5. Clear log files
Logs grow over time. Inspect with ncdu:
sudo apt-get install ncdu
sudo ncdu /var/log
Truncate a specific log file:
sudo dd if=/dev/null of=/var/log/shadowsocks.log
6. baobab — disk usage analyzer
A GUI tool to find which directory is eating space:
baobab
Or use ncdu for the user home:
sudo ncdu /home/<username>
ncdu for servers, baobab for desktops.
7. Remove large packages
Install debian-goodies:
sudo apt-get install debian-goodies
List the biggest packages:
dpigs -H
Example output:
441.0M texlive-latex-extra-doc
230.1M valgrind-dbg
200.6M chromium-browser
171.4M google-chrome-stable
153.4M linux-image-extra-3.19.0-39-generic
153.4M linux-image-extra-3.19.0-37-generic
151.5M maltego
144.8M wine1.7-amd64
140.6M metasploit-framework
137.4M wine1.7-i386
Default is top 10; use --lines=20 for more:
dpigs -H --lines=20
8. Use ubuntu-tweak to clean
Download the .deb from the official site, then:
sudo apt-get install gdebi
sudo gdebi ubuntu-tweak*.deb
Open ubuntu-tweak, pick the Janitor tab. From there you can clear app caches, thumbnail caches, apt caches, old kernels, leftover configs, and orphan packages.
Locale
Check the current locale:
locale
Generate / set locales:
sudo locale-gen en_US en_US.UTF-8 en_CA.UTF-8
sudo dpkg-reconfigure locales