npm install fails with “npm ERR! tar.unpack untar error”


npm failed randomly while installing packages. It didn’t matter which packages or if running on Debian itself or inside virtual machines using Ubuntu (vagrant). Upgrading npm to the latest version (sudo npm install -g npm@latest ) and clearing npm’s cache (npm cache clean ) didn’t help either.

After examining the downloaded temporary packages in /tmp  I realized that they were corrupt. The corrupt packages changed randomly on every download attempt. Changing the temporary directory from /tmp  to another location did not resolve the issue. Every user on the machine was affected by the problem.

Since the issue occured on every platform for every user, inside vagrant-VMs and even on different machines (Laptop, Desktop-PC, …) it was soon clear that the solution probably had nothing to do with npm.

After weeks of troubleshooting without any result I realized that the problem only ocurred when running the command at home. The command executed fine when my Laptop was inside other networks. This led me to the conclusion that the network configuration was the cause of all problems. Since all machines received their settings via DHCP my first try was to manually define the DNS settings.

Et voilà: Everything worked as expected.


Change the DNS servers you use. You’re probably using the default servers provided by your ISP. There are plenty of other public DNS servers out there. For a quick test you might even use the ones operated by Google:  and .

Posted in Debian, Node.js, Ubuntu, Vagrant | Comments Off on npm install fails with “npm ERR! tar.unpack untar error”

Simulate the environment of Cron Jobs

Often you will find yourself in the situation that one of your cron jobs works perfectly if you execute it manually but fails as soon as is gets executed by cron. The root cause might be the different environment. To simulate the environment of a cron job add the following entry to your crontab using crontab -e:

* * * * * env > /root/cronenv

This will create the file cronenv in your root directory and dump all available environment variables into it. Once the file was created remove the entry from your crontab and take a look at its contents:


This pretty much sums up the environment. To enter this environment use the following command:

env - `cat /root/cronenv` /bin/sh

Now you can execute your cron job command, see what happens and fix your error. Once you’re done simply type exit to leave the environment.

See this Stack Overflow answer for more information.

Posted in Debian, Ubuntu | Comments Off on Simulate the environment of Cron Jobs

Ubuntu: Mount encrypted home directory

After changing harddrives I needed to transfer some files from the old harddrive which had an encrypted home directory. The command

sudo ecryptfs-recover-private

did not work:

sudo ecryptfs-recover-private /home/.ecryptfs/user/.ecryptfs/
INFO: Found [/home/.ecryptfs/user/.ecryptfs/].
Try to recover this directory? [Y/n]:
INFO: Found your wrapped-passphrase
Do you know your LOGIN passphrase? [Y/n]
INFO: Enter your LOGIN passphrase...
Inserted auth tok with sig [f7402d552edaa194] into the user session keyring
mount: mount(2) failed: No such file or directory
ERROR: Failed to mount private data at [/tmp/ecryptfs.p3BXsWqk]. pointed me in the right direction. First mount the old hard drive in the new Ubuntu installation. Then run

sudo ecryptfs-add-passphrase --fnek

to add the corresponding passphrase (32 digits). Remember the second sig and mount your directory with

sudo mount -t ecryptfs /mnt/oldhome/.ecryptfs/me/.Private /mnt/oldme

You will need to answer some questions. The suggested default works except for the following two questions:

Enable filename encryption (y/n) [n]: y


Filename Encryption Key (FNEK) Signature [aaaaaaaaaaaaaaaa]: bbbbbbbbbbbbbbbb

In my case some warnings were shown saying that encryption may not have worked properly and if mounting should continue. Despite those warnings all files were accessible.

Posted in Ubuntu | Comments Off on Ubuntu: Mount encrypted home directory