Flimm's answer works. However, npm config set prefix '~/.local/' has no effect for me. There is no .npmrc file and even after I created the file, the command above still has no effect. I have to edit it manually.
npm config set prefix '~/.local/'