nvm slows down shell startup

Recently I was wondering why my shell is taking so long to show a prompt and was able to track it to nvm – node version manager. The check which version to use as default takes quite long so I was looking for a solution that allows me to keep nvm functionality and have a fast shell.

When installing nvm it tells you to add the following statement to your shell config:

export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" --no-use # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Line to of this is causes the delay in the startup. As more on the backend side of development I don’t switch node versions and so on around very often so I found a solution that let’s me disable this check, which version should be used on nvm startup by adding a default version to the path and disable that check in the startup script:

# set default node version
export PATH="~/.nvm/versions/node/v12.18.3/bin:$PATH"
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" --no-use # This loads default nvm version from above and skips default check
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

The first line set my default node version to 12.18.3 as default – which is stable right now. Then I added --no-use to the end of the second line. Now every time i start the shell node 12.18.3 will be used until i say nvm use. But that’s a tradeoff I can live with to have my shell start in an acceptable timespan again.

gradle jacoco plugin with java 15

In my latest experiments I upgraded a project to Java 15 and received exceptions during the build from jacoco that state that the used Java version isn’t supported. Here the exceptions stacktrace I received:

java.lang.instrument.IllegalClassFormatException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
        at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:94)
        at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
        at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
        at java.base/java.lang.ClassLoader.defineClass2(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1108)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:183)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:784)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:705)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:586)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:634)
        at java.base/java.lang.Class.forName(Class.java:546)
        at java.base/java.util.ServiceLoader.loadProvider(ServiceLoader.java:854)
        at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1078)
        at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1301)
        at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1386)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:89)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter$1.run(CLDRLocaleProviderAdapter.java:86)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
        at java.base/sun.util.cldr.CLDRLocaleProviderAdapter.<init>(CLDRLocaleProviderAdapter.java:86)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.forType(LocaleProviderAdapter.java:188)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.findAdapter(LocaleProviderAdapter.java:287)
        at java.base/sun.util.locale.provider.LocaleProviderAdapter.getAdapter(LocaleProviderAdapter.java:258)
        at java.base/java.util.Calendar.createCalendar(Calendar.java:1693)
        at java.base/java.util.Calendar.getInstance(Calendar.java:1661)
        at java.base/java.text.SimpleDateFormat.initializeCalendar(SimpleDateFormat.java:677)
        at java.base/java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:621)
        at java.base/java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:600)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.getLastResortErrorLogFile(SystemApplicationClassLoaderWorker.java:168)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:111)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:69)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:68)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:73)
Caused by: java.io.IOException: Error while instrumenting sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo.
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:109)
        at org.jacoco.agent.rt.internal_43f5073.CoverageTransformer.transform(CoverageTransformer.java:92)
        ... 37 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 59
        at org.jacoco.agent.rt.internal_43f5073.asm.ClassReader.<init>(ClassReader.java:195)
        at org.jacoco.agent.rt.internal_43f5073.asm.ClassReader.<init>(ClassReader.java:176)
        at org.jacoco.agent.rt.internal_43f5073.asm.ClassReader.<init>(ClassReader.java:162)
        at org.jacoco.agent.rt.internal_43f5073.core.internal.instr.InstrSupport.classReaderFor(InstrSupport.java:280)
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:75)
        at org.jacoco.agent.rt.internal_43f5073.core.instr.Instrumenter.instrument(Instrumenter.java:107)
        ... 38 more

Especially “Unsupported class file major version 59” is a good indicator that Java 15 isn’t supported yet. To get around that you need to upgrade the jacoco tool version in your gradle project by adding:

jacoco {
    toolVersion = "0.8.6"
}

You need at least 0.8.6 because there experimental Java 15 was added. You can find the release history under https://www.jacoco.org/jacoco/trunk/doc/changes.html. Right now 0.8.6 is the latest release that solves the issue without the need to go to a snapshot build of 0.8.7.

Professional audio stack for video editing/streaming

I just managed to get the audio stack of my windows 10 more professional with equalizer and VST plugins:

First I installed virtual audio cable and voicemeeter potato:

  • https://vb-audio.com/Cable/index.htm
  • https://vb-audio.com/Voicemeeter/potato.htm

With those I am able to split up all my audio sources and manage volumes per channel or add equalizers. With OBS you can install the voicemeeter plugin from https://obsproject.com/forum/resources/obs-voicemeeter.741/

Just disable all audio in the OBS settings and add Voicemeeter sources instead. You should use scene inheritance so that you don’t have to do that for every scene. With insert input sources you can grab the input from every input line of potato directly. You could then add VST plugins for every channel directly in OBS. If you want to use equalizers or plugins from potato – or change volumes there – then you need to grab the output instead and route the channel to single hardware/virtual outputs.

Next I took care of my microphone and installed equalizer APO from https://sourceforge.net/projects/equalizerapo/.

This alone wouldn’t help much so I also downloaded some VST plugins from https://www.tokyodawn.net/tokyo-dawn-labs/ and https://www.reaper.fm/reaplugs/ and created my audio stack for the microphone.

docker reset script – docker prune

I’m using docker for a lot of projects and have to switch context very often – I know – that kind of sucks, but that’s how it is…

Most containers can’t be shared between projects and I don’t want to spend more resources than necessary as my machines are on their limits. So I wrote a small bash script to get rid of all running containers, images, … on my local machine:

#!/bin/bash
echo "###########################"
echo "# clean docker"
echo "###########################"

echo "# stopping containers"
docker stop `docker ps | awk '{print $1}' | grep -v CONTAINER` >> /dev/null 2>&1

echo "# prune system"
docker system prune -f --volumes >> /dev/null 2>&1

echo "###########################"
echo "# done"

It will output a text like this

###########################
# clean docker
###########################
# stopping containers
# prune system
###########################
# done

when executed.

After that there shouldn’t be any leftovers except your images. If you also want to get rid of those you can run:

docker system prune -f --all --volumes

Or just add –all in the script above.

Attention: This will delete all your local volumes and images. So make sure you don’t run this if any data in the containers is of importance for you.

Shells starting very slow on my ubuntu and mac

My shells were starting very slow which is really bad as a dev/admin. I found out that all those version managers I installed were to blame for that. So I decided to get rid of nvm and rvm by simply removing the directories and cleaning up my .bashrc and .profile in $HOME.

#nvm
rm -rf ~/.nvm
rm -rf ~/.npm
rm -rf ~/.bower
rm .zshrc # i am using bash

#rvm
rm -rf .rvm

# cleanup configs
vim ~/.bashrc ~/.profile

After those simple steps my shell is up within an instand instead of needing some thinking time.

sdkman and brew seem to be ok and are allowed to stay installed for now.

Uninstall snapd from ubuntu 20.04

In my last post I found out who was to blame for filling my complete disk. It was this new and fu**** slow snapd added to ubuntu in the last few moments before release to get into the app market business. I decided to live without this feature and uninstalled it:

snap list | awk '{print $1}' | xargs -rn1 sudo snap remove

After letting this run a few times i tried to uninstall the remaining snaps manually with

sudo snap remove <name>

Some refused to uninstall but I continued with unmounting its volume and getting rid of snapd from the system:

sudo umount /snap/core/<replace_with_number_in_your_folder>
sudo apt purge snapd

In the end i cleaned up any stuff left from snapd:

rm -rf ~/snap
sudo rm -rf /snap
sudo rm -rf /var/snap
sudo rm -rf /var/lib/snapd

In the end removing all snaps freed about 20GB of data. I will reinstall everything based on apt as usual and will then be back at maybe 15GB of saved space without snapd.

Next to this space problem all the apt installed applications start seconds faster.

Thanks for the long years of great operating system but that’s a way I won’t go with you.

Remove old/disabled snaps from the system – ubuntu why…

The new snap system starts eating my system partition. Next to being slow it also holds old backups of upgraded snaps. Ubuntu itself has no option to disable that. You can only lower the number of old versions by using

sudo snap set system refresh.retain=2

which will limit the number to one live and one backup copy. But what if you also don’t need or want that backup copy? refresh.retain doesn’t allow 1:

sudo snap set system refresh.retain=1

error: cannot perform the following tasks:
- Run configure hook of "core" snap (run hook "configure": retain must be a number between 2 and 20, not "1")

I didn’t further check how to remove that but used the following one-liner to get rid of old versions:

sudo su
snap list --all | awk '$6~"disabled"{print $1" --revision "$3}' | xargs -rn3 snap remove

Next to those backups also the /var/lib/snapd/cache folder holds a massive amount of space on my machine. I considered it to be safe to delete:

sudo rm -f /var/lib/snapd/cache/*

This cleanup of snapd folder freed around 12GB of data on my root partition.

Stop firefox from changing your URLs automatically to https

As an admin I have to work with http and https sites quite often. Firefox started to put https in front of everything automatically and clearing the cache all the time is not what I wanted to continue. I found a quick workaround that avoids this issue. Open a new tab and enter about:config in the address bar and hit enter. Confirm the warning and the look for browser.urlbar.autoFill and disable it. With this set to false Firefox stopped that annoying behavior for me.

Get script directory in Bash

If you need to get the script directory of an executed bash script you can use the following snippet to cd to the script directory:

#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR" || exit 1

Add docker to unattended-upgrades in ubuntu 20.04

If you want your server to install docker updates automatically then you need to add the docker repository to the list of allowed origins. Otherwise docker updates will stay untouched by unattended-update which will looks similar to this when you login and check which updates need to be installed. Had that quite some times until I decided to look into this.

sudo apt dist-upgrade 
...
The following packages will be upgraded:
  containerd.io docker-ce docker-ce-cli

As you can see all docker packages (coming from https://download.docker.com/linux/ubuntu) weren’t updated. This happens because this origin isn’t in the allowed origin list of unattended-upgrade. You can see metadata of the repository by running

apt-cache policy

There you will find an entry like this

 500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
     release o=Docker,a=focal,l=Docker CE,c=stable,b=amd64
     origin download.docker.com

The important part is the o and a in this definition. Those state the origin and the archive.

To allow the docker repo as an origin you need to open /etc/apt/apt.conf.d/50unattended-upgrades with root access and add

"Docker:${distro_codename}";

to the list in Unattended-Upgrade::Allowed-Origins. The syntax is short for “origin:archive”.

Here the allowed origins list from my file as an example:

Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}";
        "${distro_id}:${distro_codename}-security";
        "${distro_id}ESMApps:${distro_codename}-apps-security";
        "${distro_id}ESM:${distro_codename}-infra-security";
        "${distro_id}:${distro_codename}-updates";
        "Docker:${distro_codename}";
};

I replaced the archive name focal with the variable distro_codename like the existing examples also did. This will help in a future dist upgrade if you plan to upgrade your os for example with the next lts version.

With those changes in place unattended-upgrade should also install updates for docker from now on.

The same procedure can be followed to add other repositories to this list as well.