[Drupal] Installing latest version of drush on Linux system and troubleshooting
https://www.zyxware.com/sites/default/files/styles/user_image/public/default_images/index.png?itok=dkp9qUXZ
BY abhai.sasidharan
6 years ago
Drupal-Technical
2 comments comment

The radical changes that Drupal 8 brought forward have been reflected in Drush 7 as well. Drush 7 now uses composer to download its dependencies. Before installing Drupal 8 you must make sure that Drush 7 has been installed. This is because Drupal 8 can be downloaded and installed using Drush like in the previous versions of Drush and also, Drupal 8 only supports Drush 7. Unlike earlier versions, Drush 7 cannot be installed using "sudo apt-get install drush" nor can it be updated by running "drush self-update" because that will result in updating to Drush 6 and no more. Hence the purpose of this article.

Drush is a powerful tool to manage routine tasks in a Drupal site. Downloading, installing or enabling modules, running cron and much more can be accomplished using Drush. This is why its important to have Drush 7 before a Drupal 8 installation. Drupal 8 requires minimum version of PHP 5.4. Apache requirements haven't been mentioned, but I recommend apache2.4. After this we can begin installing Drush 7.

Installing Composer

As I have mentioned earlier, Drush uses composer to install its dependencies, so first we have to install composer. Install composer globally on your system or server because with Drupal 8 composer will be required quite often.

  • To download composer, you will have to run the command "curl -sS https://getcomposer.org/installer | php". Make sure you have permissions. Run this command from the home folder. If curl is not installed in your system, run "sudo apt-get install curl". curl is a tool to transfer data from or to a server, using one of the supported protocols. Run "man curl" for more details.
  • After it has been downloaded, run "sudo mv composer.phar /usr/local/bin/composer". Now you can run "composer --version" to see if its working.

Installing Drush

  • Remove any earlier versions of Drush if installed, otherwise it will cause conflicts.
  • Run "composer global require drush/drush:dev-master" from the home folder. Make sure you have permissions or run with sudo. This will give you the latest version of Drush.
  • If all goes well you will see an output like this :
      
        Changed current directory to /home/user/.composer
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
      - Installing pear/console_table (1.1.5)
        Downloading: 100%
     
      - Installing symfony/yaml (v2.2.1)
        Downloading: 100%
     
      - Installing d11wtq/boris (v1.0.8)
        Downloading: 100%
     
      - Installing drush/drush (dev-master 6ce7202)
        Cloning 6ce72029d154abe9cf8d0a7c8d7ebf44d511294a
     
    pear/console_table suggests installing pear/Console_Color (>=0.0.4)
    drush/drush suggests installing youngj/httpserver (dev-master#41dd2b7 as 1.0.1) 
       
    
  • This will install in the directory: ~/.composer/vendor/drush/drush, so we will have to set path.
    • ln -s /home/<linux user name>/.composer/vendor/drush/drush /usr/bin/drush
    • export PATH="$PATH:/home/<linux user name>/.composer/vendor/drush/drush:/usr/local/bin"
  • Run "drush status" to see if drush has been installed.
  • We have to edit the .bashrc file and include the export statement in it, otherwise the PATH variable set will not be reflected in every bash terminal instance.
    • Run "gedit .bashrc" on terminal at the home folder. If .bashrc does not already exist, you can create one now.
    • At the beginning of the document, include the line " export PATH="$PATH:/home/<linux user name>/.composer/vendor/drush/drush:/usr/local/bin" ", save the file and exit.
  • The .bashrc file will be executed every time the terminal or any bash console is run. This will set the PATH variable every time bash runs.
  • Open a new terminal and run "drush status" to see whether this has worked.

Troubleshooting

If running "drush status" gives an error "drush is not installed. Run sudo apt-get install drush", then either Drush installation did not go as planned or the PATH variable was not set properly.

  • Run "echo $PATH" and check whether Drush path is there in your PATH variable.
  • This is how a normal PATH variable looks in an ubuntu system :

    /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/user/.composer/vendor/drush/drush:/usr/local/bin

  • Make sure you did not change anything else in the .bashrc file and that you have write permissions.
  • Go to the Drush installation folder: .composer/vendor/drush/drush and check whether Drush has been downloaded there. This can happen if, either you did not have the required permissions or if there was a problem with connection on either end and the request timed out.
  • In that case run "composer global require drush/drush:dev-master" again or navigate to .composer/ folder from terminal and run "composer update drush"
  • To update composer, navigate to .composer/ and run "composer update". This will also update drush/drush:dev-master.

Drush is important and essential to work alongside with Drupal.With composer, a powerful dependency manager, it is easier to download and install Drush. Once set up, Drush 7 and Drupal 8 is something that gets any web developer excited!

References:


RELATED ARTICLE

/themes/custom/zyxpro_light/images/placeholder.png
close

on 01st January 2008 / by webmaster
We have added a few new modules to our site recently. Drupal Technical StumbleThis Sean (not verified) access_time 21 Sep 2021 - 18:10 Hi there, I uploaded the files, enabled the modules to use SU, and now I see the link, but there is no icon... How can I fix this? Thanks, Sean webmaster access_time 21 Sep 2021 - 18:10 In reply to Icon doesn&#039;t show by Sean (not verified) What do you see when you view the source? Search for stumblethis_button and you should be able to see the code for the image and the URL. Then you should be able to troubleshoot from there. Juicy Couture Addict (not verified) access_time 21 Sep 2021 - 18:10 thanks for the post. would love to hear more of you. by the way, drupal's really popular nowadays as it has easy and fast features. you agree with me? thanks.
/themes/custom/zyxpro_light/images/placeholder.png
close

on 16th January 2008 / by webmaster
Most webmasters do not realize this, but a lot of the content on lot of websites can be accessed from multiple URLs. A simple example would be where www.example.com and example.com leads to the same page. This is a fatal mistake in Search Engine Optimization and search engines penalize you for duplicate content. The correct configuration would be where the above two urls will lead you to the same page but example.com will redirect you to www.example.com with a 301 (Moved permanently) status which will not result in search engines penalizing the page. It is very easy to configure 301 redirects using Apache .htaccess file and the process is the same for a Drupal installation also. Drupal Technical Apache htaccess SEO Anonymous (not verified) access_time 21 Sep 2021 - 18:10 Hello. I'm trying to make example.com show as www.example.com, and I'm running into difficulties. I'm on Apache 2.0 and using the following lines in my httpd.conf file: RewriteEngine on RewriteCond %{HTTP_HOST} ^xxxxxxxxxx\.com$ [NC] RewriteRule ^(.*)$ http://www.xxxxxxxxxx.com/$1 [L,R=301] When I go to http://xxxxxxxxxx.com, I get http://www.xxxxxxxxxx.com (as expected). However, when I go to http://xxxxxxxxxx.com/node/1 (it's a Drupal site), I get a 404 thrown and the URL changes to xxxxxxxxxx.com/var/www/drupal/node/1. Same thing with www.xxxxxxxxxx.com/node/1. Any suggestions? I want to run without Drupal's .htaccess file (instead incorporating these calls into my httpd.conf file). webmaster access_time 21 Sep 2021 - 18:10 In reply to Rewrite including filesystem path by Anonymous (not verified) I think the problem is with the base path which results in the redirection to /var/www/ part. The best approach I would think is to start with drupal htaccess and then strip out parts and move to httpd SNVC (not verified) access_time 21 Sep 2021 - 18:10 This is definitely a good guide. Thanks for this. wellyson access_time 21 Sep 2021 - 18:10 This is really nice and helpful.
/themes/custom/zyxpro_light/images/placeholder.png
close

on 08th February 2008 / by webmaster
Attachment Size slashdotit.tar.gz 173.55 KB Similar to the StumbleThis module that we had created earlier we have created another bookmarking Drupal Technical Slashdotit Shlomi Fish (not verified) access_time 21 Sep 2021 - 18:10 Hi! I'm interested in this module, but Drupal 6.2 complains that it's incompatible with it. Can you please update it or tell me how? Regards, Shlomi Fish shlomifish.org webmaster access_time 21 Sep 2021 - 18:10 In reply to Can you update it for Drupal-6.x? by Shlomi Fish (not verified) Sure we are working on this currently and will post an update soon. Also we will post this module on www.drupal.org as well Cheers Anoop John Team Zyxware Anonymous (not verified) access_time 21 Sep 2021 - 18:10 Hello! Nice Article very interesting, thanks

Comments


author-image
Anonymous (not verified)
access_time 22 Sep 2021 - 00:15

hey !
many thanks for this page.
I would like to add my story :
- I'm using ubuntu via ssh
- after having set the $PATH into .bashrc and starting a new ssh session, nothing happened. still the message : "drush is not installed. Run sudo apt-get install drush"
- I had to put the PATH config into ~/.bash_profile to make it work.

just my two cents ;)


author-image
kjohnah (not verified)
access_time 22 Sep 2021 - 00:15

very helpful guide but the path where composer downloads drush is different on ubuntu 16. So one needs: sudo ln -s ~/.config/composer/vendor/drush/drush /usr/bin/drush
and then:
export PATH="$PATH:~/.config/composer/vendor/drush/drush:/usr/bin"
Also the editing the bashrc file might be unnecessary as it does not affect the output of drush status afterwards