Drupal - When attempting to run drush ": No such file or directory"

I was getting this same error when running drush commands on a remote computer via a drush alias. I could run the same drush commands on the remote system directly with no problems but when I would try to run them via a drush alias (@remotesystem) I would get this error.

I found that the user on the remote systems default shell was sh and not bash. Because the bash configuration file ~/.bashrc contains the line that adds the location of drush to the path the sh shell was not able to find drush as ~/.bashrc will not be sourced by the sh shell only by bash.

The drush installation instructions on docs.drush.org state:

Now add Drush to your system path by placing export PATH="$HOME/.composer/vendor/bin:$PATH" into your ~/.bash_profile (Mac OS users) or into your ~/.bashrc (Linux users).

You can check what your current shell is set to by running:

export |grep SHELL

This will print a line with your current shell in it like this:

declare -x SHELL="/bin/bash"

On Ubuntu the default shell is sh but the default user shell is bash. This happened on a Ubuntu Server install (no GUI).

To fix this change your default shell to bash.

For current users run the following to change the default shell:

sudo -u <USERNAME> chsh -s /bin/bash

For future users, if you use useradd, edit the /etc/default/useradd skeleton file (don't forget to make a backup though). Change the line:

SHELL=/bin/sh

to

SHELL=/bin/bash

This will set bash as the shell for new users that are created.

Tags:

Drush