Ubuntu tips and tricks

From HPCWIKI
Jump to navigation Jump to search

Set default text editor

$ sudo update-alternatives --config editor (on Ubuntu)
...
  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
* 3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    15        manual mode

Press <enter> to keep the current choice[*], or type selection number: <enter the number>

glibcxx_3.4.26 not found

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-9
sudo apt install libstdc++6

Dealing with Old kernel

# get current running kernel
$export kv=$(uname -r | awk -F '-virtual' '{ print $1}')

# list all other installed kernel
$dpkg --list | egrep -i 'linux-image|linux-headers' | awk '/ii/{ print $2}' | egrep -v "$kv"

# remove other kernels
$sudo dpkg -r $(dpkg --list | egrep -i 'linux-image|linux-headers' | awk '/ii/{ print $2}' | egrep -v "$kv")

Remove GUI packages

#To remove x11 and everything that uses it, including all configuration:

$sudo apt-get purge -y libx11.* libqt.* libgtk.* xserver-xorg-core X11-* libwayland-*
$apt-get purge $(apt-cache depends gnome | grep Depends | awk '{print $2}')
$sudo apt-get autoremove -y

Switching boot target to text

$systemctl get-default                  #Find which target unit is used by default
$sudo systemctl set-default multi-user.target  #To change boot target to the text mode
$sudo systemctl reboot                  #Reboot the system

The following packages have been kept back[1]

There are 3 categories of reasons for packages being kept back during apt upgrade

  • It is marked as held back

apt-mark can do this:

sudo apt-mark hold <package>

To list all packages marked on hold or find out if a package is on hold use:

<apt-mark showhold
apt-mark showhold <package>

To remove a hold on a package and allow it to be upgraded:

sudo apt-mark unhold <package>
  • apt detects a dependency change

This will tell you the current and candidate upgrade versions of the package:

$ apt list <package>

we can figure out the changed dependencies with apt show:

apt show <package>=<old version> <package>=<new version>

The important parts are the Depends and Recommends package lists. If there are new packages in those lists in the new version of the kept back package, apt won't automatically upgrade it

  1. To upgrade the package and install any new "Recommended" packages (i.e. as if newly installed with apt install <package>, use --with-new-pkgs:
    $sudo apt upgrade --with-new-pkgs <package>
    (Tip: add --dry-run to see what will happen before doing it)
    
  2. To upgrade the package without installing any newly added "Recommended" packages, use --only-upgrade.
$sudo apt install --only-upgrade <package>
  • Phased updates
    You can check for phased updates with: sudo apt -o APT::Get::Always-Include-Phased-Updates=true upgrade --dry-run

The following security updates require Ubuntu Pro with 'esm-infra' enabled

the file /etc/apt/apt.conf.d/20apt-esm-hook.conf provides the hook that calls the marketing message generation. Removing that is an option[2]

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

after then run apt upgrade the message does not show

How to cleanly remove x11[3]

sudo apt purge 'x11-*'
sudo apt autoremove

apt-get update “the following signatures couldn’t be verified because the public key is not available”

$ sudo apt update
Err:5 https://packages.cloud.google.com/apt kubernetes-xenial InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B53DC80D13EDEF05
  
#need to add the missing Key B53DC80D13EDEF05
$sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B53DC80D13EDEF05
Executing: /tmp/apt-key-gpghome.xfmtcCbrXz/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys B53DC80D13EDEF05
gpg: key B53DC80D13EDEF05: 1 duplicate signature removed
gpg: key B53DC80D13EDEF05: public key "Rapture Automatic Signing Key (cloud-rapture-signing-key-2022-03-07-08_01_01.pub)" imported
gpg: Total number processed: 1
gpg:               imported: 1

#now update will be successful

References