Skip to content

2024-10

Ubuntu postinstall

Things to do after installing

Make software repo point to NCHC for faster network speed

You can replace  archive.ubuntu.com with a closer mirror, e.g., tw.archive.ubuntu.com or free.nchc.org.tw in /etc/apt/sources.list.d/ubuntu.sources. After you are done, run:

sudo apt clean && sudo apt update && sudo apt full-upgrade -y

Install 3rd party apps

First, install required package

sudo apt update && sudo apt install -y apt-transport-https ca-certificates curl git gnupg-agent software-properties-common

Brave browser

Setup Brave browser

sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://brave-browser-apt-release.s3.brave.com/brave-browser-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/brave-browser-archive-keyring.gpg arch=amd64] https://brave-browser-apt-release.s3.brave.com/ stable main" | sudo tee /etc/apt/sources.list.d/brave-browser-release.list > /dev/null
sudo apt update && sudo apt install -y brave-browser

Git

sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update && sudo apt install -y git git-lfs

qBittorrent

sudo add-apt-repository -y ppa:qbittorrent-team/qbittorrent-stable
sudo apt update && sudo apt install -y qbittorrent

Telegram messenger

Download and run the official binaries.

Xanmod Linux kernel

Xanmod is a general-purpose Linux kernel distribution with custom settings and new features.

curl -fsSL https://dl.xanmod.org/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/xanmod-keyring.gpg
echo 'deb [signed-by=/usr/share/keyrings/xanmod-keyring.gpg] http://deb.xanmod.org releases main' | sudo tee /etc/apt/sources.list.d/xanmod-kernel.list > /dev/null
sudo apt update && sudo apt install -y linux-xanmod

AMD and Intel open-source GPU library (Mesa)

Install the latest Mesa open source GPU drivers from the kisak PPA

sudo add-apt-repository -y ppa:kisak/kisak-mesa
sudo apt update && sudo apt full-upgrade -y

Wine and 32-bit games support

sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/noble/winehq-noble.sources
sudo apt update && sudo apt install wine

Kubuntu backports

Kubuntu backports: Latest versions of KDE framework and APPs

sudo add-apt-repository -y ppa:kubuntu-ppa/backports
sudo apt-get update && sudo apt full-upgrade -y

Latest kernel

Install Hardware Enablement (HWE) kernels: https://ubuntu.com/kernel/lifecycle

sudo apt install --install-recommends linux-generic-hwe-$VERSION

Where $VERSION is the Ubuntu version.

Update your system and install packages

sudo apt update && sudo apt full-upgrade -y

Ubuntu:

sudo apt install -y git git-lfs cifs-utils ssh nala gnome-shell-extension-manager parallel baobab ncdu synaptic apt-xapian-index ppa-purge ubuntu-restricted-extras ffmpeg vlc mcomix fonts-wqy-microhei fonts-wqy-zenhei fonts-open-sans ttf-mscorefonts-installer zsh btrfs-compsize

Kubuntu:

sudo apt install -y git git-lfs cifs-utils ssh nala parallel ncdu kio-extras gnome-keyring ppa-purge kubuntu-restricted-extras ffmpeg vlc fonts-wqy-microhei fonts-wqy-zenhei fonts-open-sans ttf-mscorefonts-installer zsh btrfs-compsize synaptic apt-xapian-index

System tweaks

Fix locales

Uncomment the zh_TW line in /etc/locale.gen. Then run:

sudo locale-gen

Finally, install the Traditional Chinese locale in Language Support and then set locale to Taiwan.

(Optional) Remove snap

List snap packages

snap list

Uninstall each Snap package

sudo snap remove --purge $PKG

Stop the snapd service and uninstall it

sudo systemctl stop snapd
sudo apt remove --autoremove --purge snapd
sudo apt-mark hold snapd

Terminal

Temporary files in RAM disk

Setting tmpfs (RAM disk) for /tmp folder:

sudo cp -v /usr/share/systemd/tmp.mount /etc/systemd/system/
sudo systemctl enable tmp.mount

Disable Extended Security Maintenance (ESM)

sudo mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.disabled

Disable cloud-init

sudo touch /etc/cloud/cloud-init.disabled

Automatic updates

sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Gnome shell extensions

YOu can also search and install extensions via gnome-shell-extension-manager

Kubuntu System Settings

  • Double click to open files instead of single clicks: Workspace behavior => General behavior => click behavior.
  • Start with an empty session in Desktop session.

Making system more responsive

Fine-tuning the kernel

Replace the line in /etc/default/grub

Gaming:

/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash preempt=full"

Virtualization:

/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash preempt=full Nohz_full=all"

Then run:

sudo update-grub

Misc.

Git Commands

Sources:

Ordinary workflows

HEAD: the current state of the repo.

Download a repository

Clone a git repo from a remote repository:

git clone <url>

Checking out a specific branch:

git clone <url> -b <branchname>

If there are submodule(s) in the Git repository, you might want to clone them as well using the --recursive option.

git clone <url> --recursive

See also: SSH login to Git services like GitHub and GitLab.

Make changes and commit

git status      # The current state of the repository.
git add <file>  # Add a new or edited file to the staging area. i.e. telling git to track this file
git add -A      # Track all files at once
git commit -m "Commit message"  # Commit staged (added) file
git commit -am "Commit message" # Commit modified files without having to run git add beforehand
git revert <SHA>                # Make a counter commit to undo the changes. The tracked files will go back to the <SHA> commit.

Synchronize with remote: Push and pull

git fetch # Download objects and refs from another repository without really pull in the changes
git merge # After git fetch, merge the changes done in the remote to the local repo
git push <remote> <branch-name> # Push commits in to remote
git push --set-upstream <remote> <name-of-your-branch>  # Setup remote url before push
git pull <remote>  # Pull changes from the remote

Stash

To temporarily store untracked files.

git stash -u   # Store current work with untracked files
git stash pop  # Bring stashed work back to the working directory

Work with branches

git branch <branch_name>    # Create a new branch
git branch -a               # List all branches
git branch -d <branch_name> # Delete a branch

git checkout <branch_name>    # checkout an existing branch
git checkout -b <branch_name> # Create a new branch and checkout it

git switch <branch_name>    # Switch to a specified branch. If the branch name does not exist, create one.
git merge  <branch_name>    # Merge the branch into the current branch

Orphan branches

Orphan branches are unrelated to others in history. For example, gh-pages branch dedicated to GitHub pages.

git branch --orphan <branchname>  # Create a orphan branch

Install fonts in Linux

Copy the fonts files to ~/.local/share/fonts/. Then, run fc-cache to rebuild fonts cache.

fc-cache -fv

Git submodule

Frequently used commands for Git submodules.

Add a submodule

TO add the reference to another git project as a submodule:

git submodule add $url $path
git submodule update --init --recursive

Alternatively, you can use GUI tools like or GitHub desktop. They download and initiate submodules automatically.

Add you will see the file .gitmodules with information about the submodule(s). For instance,

.gitmodules
[submodule "themes/DoIt"]
    path = themes/DoIt
    url = https://github.com/HEIGE-PCloud/DoIt.git

Track a specific branch in the submodule

With -b $branch option

git submodule add -b $branch $url $path

Or set-branch -b $branch if you already have added a submodule

git submodule set-branch -b  $branch $path

Update all Git submodules to the latest commit

From a stackOverflow post and Git docs

git submodule update --remote --merge

For automated updates by bots, see automatic dependency update.

Remove a submodule

From Git docs

# Remove submodule from config
git submodule deinit $path
# Delete submodule tracking data
git rm <submodule path> && git commit
# Complete removal
rm -rf $GIT_DIR/modules/$name/

SSH login to GitHub and GitLab

Generate a pair of SSH keys

ssh-keygen -t ed25519 -C "your_email@example.com"

The SSH agent will ask you to enter a location to save the keys. e.g. /home/user/.ssh/id_ed25519. Passphrase is optional.
Then there will be two SSH key files:

  • ~/.ssh/id_ed25519 is the private key. Protect it at all costs.
  • ~/.ssh/id_ed25519.pub is the public key.

Using different keys for GitHub and GitLab access is more secure. However, the same pair of keys is used for this demonstration purposes.

Add remote to the SSH settings

Edit ~/.ssh/config

mkdir -p ~/.ssh
touch ~/.ssh/config
chmod 600 ~/.ssh/config
nano ~/.ssh/config

Add the following content to set the private key as the IdentityFile.

~/.ssh/config
Host GitHub
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519

Host GitLab
  HostName gitlab.com
  IdentityFile ~/.ssh/id_ed25519

Add the SSH key to your GitHub account

According to 📖 Github docs, add the SSH key here

  • Paste the content of the public key, ~/.ssh/id_ed25519.pub to the key field.
  • Add a descriptive label for the new key in the "Title" field.
  • Finally, click the Add SSH key green button. If prompted, confirm your GitHub password.

Add the SSH key to your GitLab account

Add the SSH key here

  • Paste the content of the public key, ~/.ssh/id_ed25519.pub to the key field.
  • Add a descriptive label for the new key in the "Title" field.
  • Select an expiration date.
  • Finally, click the Add key button.

Test your setup

GitHub:

ssh -vT git@github.com

Accept its fingerprint if prompted. If you see "Hi user! You've successfully authenticated, but GitHub does not provide shell access" that means login is successful.

GitLab:

ssh -vT git@gitlab.com

Accept its fingerprint if prompted.

Strip Jupyter Notebook Output

Jupyter notebooks without multimedia outputs are more friendly to source control since git is not good at comparing binary data (e.g., plots, pictures, videos) in jupyter notebooks. And they tend to bloat the size of git repositories.