Category Archives: Quick Fixes

Issues running npm & WSL2 (bad interpreter)

I started a new project and wanted to use node/npm inside of WSL2. However, when I tried to run npm inside of either Ubuntu 18 or 20, I got this error message:

mark@LAPTOP:~$ npm
-bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory

After a whole lot of searching, I came across this web page, https://stackoverflow.com/questions/63716587/in-wsl2-ubuntu-20-04-for-windows-10-nodejs-is-installed-but-npm-is-not-working which suggested updating the ~/.bashrc file to look like:

# strip out problematic Windows %PATH%
PATH=$(echo "$PATH" | sed -e 's/:\/mnt.*//g')

I added that to the VERY end of the file, and rebooted.

The next time I tried to run npm, I got this successful message instead:

mark@LAPTOP:~$ npm

Usage: npm <command>

where <command> is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm <command> -h  quick help on <command>
npm -l            display full usage info
npm help <term>   search for help on <term>
npm help npm      involved overview

Specify configs in the ini-formatted file:
    /home/mark/.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config

npm@6.14.4 /usr/share/npm

Virtualbox – Your VM has become “inaccessible

Today, when I tried to boot up my linux virtualbox, I got this error:

C:\home\linux>vagrant up
Bringing machine 'default' up with 'virtualbox' provider... Your VM has become "inaccessible." Unfortunately, this is a critical error with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBox and clear out your inaccessible virtual machines or find a way to fix them.

That doesn’t sound good. A bit of googling around let me to this solution., which I’ll break down into the steps that worked for me.

In my “C:\Users{user}\VirtualBox VMs{vm-id}” folder are two files

  • {vm-id}.vbox-prev
  • {vm-id}.vbox-tmp

Renaming “{vm-id}.vbox-tmp” to “{vm-id}.vbox”

Then try running “vagrant up”

BOOM. It was that easy.

If you are unable to connect to git server over https

NOTE: Make sure you know/trust the server you are communicating with in the first place

Sometimes, git servers can have issues with TLS or other secure handshaking procedures. This is often due to connecting from an older linux/ubuntu box. If you are truly desperate and don’t have time to fix the SSL/TLS properly, here is a very quick fix:

export GIT_SSL_NO_VERIFY=1

Then run your normal git fetch or git push command.

Testing a website at its new IP address

How do you check that your new website is working without updating the DNS for the domain?

Well, if you know the new IP address, you can “trick” your home computer/browser to show the site you want, rather than the old site.

1) For Windows 7, click on the Start Menu, choose “All Programs” >> Accessories.
Next right-click on Notepad, and choose “Run as administrator”

2) Choose File, then Open…
In the File name: type in c:\windows\system32\drivers\etc\*.*
Find the “hosts” file, click on it, then click on the “Open” button.

3) Scroll down to the very bottom of the file, and add in a new line in this format, IP Address (whitespace) domain name:


111.222.33.44     www.example.com
44.55.66.77       new.example.com

Once you save the file, you’ll instantly be able to type in the domain name that you want to test. With the above example, that means typing in http://new.example.com will take you to the server at the IP address of 44.55.66.77. And if instead you typed in http://www.example.com, you would hit the server located at 111.222.33.44.

Have your bash prompt tell you git information

While you can obviously type in “git status” to see what’s happening (git-wise) in a directory, wouldn’t it be nice if you could automagically see that info?

Well, you can. Just add this snippet to your ~/.bash_profile file:

[code lang=”bash”]
if [ -f /etc/bash_completion.d/git ]; then
. /etc/bash_completion.d/git
PS1=’\[\u@\h \e[33m\]\w\[\e[0m\] $(__git_ps1 " (%s)")\n\$ ‘
fi
[/code]

Or, if that file doesn’t exist, you can create it with all of this code:

[bash]
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
if [ -f /etc/bash_completion.d/git ]; then
. /etc/bash_completion.d/git
PS1=’\[\u@\h \e[33m\]\w\[\e[0m\] $(__git_ps1 " (%s)")\n\$ ‘
fi

####
# Stash away examples of other possibilities for the prompt
#####
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ‘
# PS1=’\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$’
# PS1='[\u@\h \W$(__git_ps1 " (%s)")] \[\e[33m\]\w\[\e[0m\]\n\$’
[/bash]


Update!

I tried this on an older server that didn’t have /etc/bash_completion.d on it, and here’s how I got it to work.

1) Downloaded the latest stable version of https://github.com/telemachus/bash_completion.d and copied that directory into /etc/bash_completion.d

2) Created a symbolic link:
[bash]
ln -s /etc/bash_completion.d/git-completion.bash /etc/bash_completion.d/git
[/bash]

3) If you get this error:
[bash]
-bash: __git_ps1: command not found
[/bash] then you will need to add this

[bash]
if [ -f /etc/bash_completion.d/git-prompt.bash ]; then
. /etc/bash_completion.d/git-prompt.bash
fi
[/bash]

before the call to . /etc/bash_completion.d/git

Make vim “more readable” on black backgrounds

I pretty much live inside of putty/ssh. My defaults are a black background with white/light lettering. However, when I first get to a new system, I find that this is one of the first things that I need to change. Makes reading comments in code sooo much easier.

vim-before-background-dark

So, go ahead and modify /etc/vim/vimrc
[bash]
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
[/bash]

and remove the ” (double quote) from in front of set background=dark. This uncomments it, and makes that set vcommand visible to vi.

[bash]
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
set background=dark
[/bash]

vim-after-background-dark