2

I'm fairly new to terminal and very new to Drush - I've installed Drush on my VPS using Composer and when I ssh as root all works fine. However I realise I shouldn't be using root so am trying to set up using another user but keep getting:

env: drush: No such file or directory

I realise this is something to do with the path to drush but cannot work out what I've got wrong. Here are my .bashrc and .bashprofile contents:

ROOT .bashrc:

# .bashrc

# To fix 'stdin is not a tty' error with Drush alias connections
export PATH=$PATH:~/.composer/vendor/drush/drush
[ -z "$PS1" ] && return

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

ROOT .bash_profile:

# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH

USER .bashrc:

# .bashrc

# To fix 'stdin is not a tty' error with Drush alias connections
export PATH=$PATH:~/.composer/vendor/drush/drush
[ -z "$PS1" ] && return

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias drush='~/.composer/vendor/drush/drush'

USER .bash_profile

# .bash_profile

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

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH

I've googled lots of solutions and tried various things so may by now have a bit of a mash up of things in these files!

2
  • 1
    so drush works when as root, right? try the answer here, to give all users access to drush
    – No Sssweat
    Commented Feb 2, 2017 at 12:57
  • just tried that but no joy sadly - theirs was a different error - 'drush: command not found' - mine is 'env: drush: No such file or directory' - yes drush works as root
    – iain-g
    Commented Feb 2, 2017 at 13:12

2 Answers 2

3

You installed Drush in ~/.composer/vendor/drush/drush. You could instead use this alternative method.

If you need Drush installed for all users on a system using Composer, install Composer globally then follow the steps below.

Important: Run these shell commands as a privileged user with write access to /opt and /usr/local/bin or prefix with sudo.

# Create and/or navigate to a path for the single Composer Drush install.
mkdir --parents /opt/drush-8.x
cd /opt/drush-8.x
# Initialise a new Composer project that requires Drush.
composer init --require=drush/drush:8.* -n
# Configure the path Composer should use for the Drush vendor binaries.
composer config bin-dir /usr/local/bin
# Install Drush. 
composer install

For Drush 8, the alternative method is described on Install (alternatives) / Install a global Drush via Composer.

Follow the instructions below:

  1. Install Composer globally.
  2. Install the cgr tool following the instructions in that project.
  3. Add Composer's bin directory to the system path by placing export PATH="$HOME/.composer/vendor/bin:$PATH" into your ~/.bash_profile (Mac OS users) or into your ~/.bashrc (Linux users).
  4. Install latest stable Drush: cgr drush/drush.

For latest Drush releases, it's recommended to add it as Composer dependency, but not globally.

1
  • I tried to do this as root, but then Composer said not to run as root, so I switched to another user. Now I'm getting an error because root is the owner of the directory.
    – iain-g
    Commented Feb 2, 2017 at 17:51
2

env: drush: No such file or directory is most likely coming from the line in your .bashrc file pointing to a non-existant file/directory called drush.

Since you say you're new to terminal and drush, here's a little background of what I think is happening: The squiggly line ~ ('Tilde' iirc?) is a shortcut in terminal. It means my home directory. So if your root user's .bashrc contains a directory path starting with tilde, for example ~/.composer/vendor/drush/drush, this is basically pointing to /home/root/.composer/vendor/drush/drush. When the .bashrc file in your user's directory has the exact same line, it points to a different directory, because of the tilde. Yours will be pointing to /home/iain-g/.composer/vendor/drush/drush (hypothetically, if your linux login is iain-g).

You can't simply point to /home/root from your own .bashrc either, since you won't have permission to access the root user's home directory.

So what you need to do is:

  • Uninstall the drush you have installed for root user (otherwise you may get issues later on with 2 drushes). This may not be necessary but it's nice to clean up after yourself.
  • Install Composer globally. You're most likely safe to go with /usr/local/bin/ as the directory to put the composer file in. But if you're unsure you can type echo $PATH in terminal and you'll see all the directories in your PATH environment variable, you can put composer in almost any of these directories.
  • Install Drush For ALL USERS via Composer (see 2nd heading). It's only about 5 commands. And they're written for you. Just copy and paste and execute them line by line.
1
  • Thanks for the clear explanation Beebee, got it working now from Rudic's earlier answer, but I'll go back and uninstall the other drush as you suggested and thanks for the link to do that!
    – iain-g
    Commented Feb 2, 2017 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.