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!

  • 1
    so drush works when as root, right? try the answer here, to give all users access to drush – No Sssweat Feb 2 '17 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 Feb 2 '17 at 13:12
2

You have installed drush in the user home directory ~/.composer/vendor/drush/drush. Use this alternative method:

Install Drush for all users via Composer

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

https://getcomposer.org/doc/00-intro.md#globally

http://docs.drush.org/en/master/install-alternative/

  • Thanks Rudic - tried to do this as root - made the drush-8.xdirectory OK and moved into it, but then composer said don't run as root, so I switched to another user but now I'm getting an error because root is the owner of the directory (told you I was knew at this!) - I'll change the owner and try again :) – iain-g Feb 2 '17 at 17:51
1

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.
  • 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 Feb 2 '17 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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