• Install composer globally:
    $ curl -sS https://getcomposer.org/installer | php
    $ sudo mv composer.phar /usr/local/bin/composer
  • Install drush globally (for your user), you can specify the version:
    $ composer global require drush/drush:7.*
    
  • Add the composer path to your path (in your *.bashrc* or *.zshrc* or other):
    export PATH="$HOME/.config/composer/vendor/bin:$PATH"
    

While not recommended, Drush can easily be installed on Ubuntu by using Aptitude or apt-get. If you have sudo rights the quickest way to install Drush is from the Ubuntu repository:

$ sudo apt-get install drush

However, the version this currently will give you is 4.5 (using Ubuntu 12.04). Newer versions have many improvements so you should use Drush to upgrade itself to the latest stable:

$ sudo drush dl drush --destination='/usr/share'

Then you can check the update has been successful by executing:

$ drush --version

You could also install Drush manually by downloading it directly from the project page and following the instructions of the README.txt file.

For Ubuntu 10.04 LTS apt-get will provide 2.0 Drush version, you need to follow Ubuntu help support to enable backports and so have 4.4-1 version available, which can then by upgraded to 5.6 as described above.

$ sudo apt-get install -t lucid-backports drush

Comments

aiwata55’s picture

As of Sep/15/2011, Ubuntu 10.04 downloads and installs Drush 2.x with this method.

nidash’s picture

sudo apt-get install drush
on 11.04 gave me drush 4.4. must add doing 'drush dl drush' upgraded my drush version to 4.5

Anonymous’s picture

cool .. if you want you can just click the edit tab on top of the page and completely rewrite it

seaji’s picture

drush dl drush -- not working

message in ssh terminal:
There is no *recommended* release for project drush on Drupal 6.x. [ok]
Ask the maintainer to review http://drupal.org/node/197584 and
create/recommend a release in order to be compatible with drush and
the drupal.org security broadcast system. A recommended development
snapshot release is sufficient. Alternatively, run pm-releases
command and explicity pm-download any non-recommended release that
might be available.

seaji’s picture

Not working
sudo apt-get install drush - not working

Linux server 2.6.35-22-server #35-Ubuntu SMP Sat Oct 16 22:02:33 UTC 2010 x86
_64 GNU/Linux
Ubuntu 10.10

drush status
parse_ini_file(/usr/share/drush/includes/../drush.info): failed to [warning]
open stream: No such file or directory environment.inc:1012
PHP configuration : /etc/php5/cli/php.ini
Drush version:
Drush configuration :

PS "Installing Drush on Shared Hosting Accounts" not working as well (http://drupal.org/node/1181480)
not found "drush" command

~/drush/drush status
unknow command "status"

Bad Bad

dqd’s picture

as you wrote: you use Ubuntu 10.10

... and what does the docs say in one of the first lines? ;-)

Thanks to all for all the contributions and efforts here and everywhere else on Drupal.org!
You all rock! ~ dqd (formerly diqidoq)

bfr’s picture

Works fine on 10.04.

TipiT’s picture

If you run sudo apt-get install drush drush is installed /usr/share/drush as default. So /usr/share/drush/drush has to executable in your $PATH environment variables (I think it is but check is by running in shell export).

Update from 4.4 (available from Ubuntu repo)

After sudo apt-get install drush
1. Run sudo drush dl drush.
2. Run sudo drush.
3. drush --version

Update further

Drush might let you know that "A newer version of drush, 7.x-5.0-rc4, is available..." is available. Running
1. sudo drush self-update
2. sudo drush
3. drush --version

Should work.

Energyblazar’s picture

The above given steps work perfectly......but just one more simple thing, do restart your pc, and then type drush --version

zarexogre’s picture

Hi, I can do the above but I want to instal the dev version of drush and cant find any docs anywhere. Can anyone help advise. This is because drush 5.1 now has drush_make in core and it doesnt work right: see bug http://drupal.org/node/1539076

darthanubis’s picture

You are running the provision script as the root user. Exiting

12.04

kpastore’s picture

Steps 1 and 2 worked for my Ubuntu 12.04 installation. Upgraded to version 7.x-5.8. Thanks!

nateB’s picture

But this one did: http://solutions-architecture.com/wiki/installing-drupal-drush-ubuntu-1004

Long and short:

  • Download Drush from the project page.
  • Upload and extract the Drush archive to /usr/local/lib/ (or wget it from there, I reckon)
  • Make drush executable: sudo chmod +x /usr/local/lib/drush/drush
  • Add a symlink in the /usr/bin/ directory: sudo ln -s /usr/local/lib/drush/drush drush
  • Navigate (to one) of your site(s) folder, cd /srv/www/yoursite.com/sites/default
  • Check status of Drush with drush status
  • Check the version of Drush with drush --version. For me, it's 5.8.
markbannister’s picture

In order to not have to run as root or sudo rights see http://drupal.stackexchange.com/questions/20496/is-it-possible-to-run-drush-without-root

summary:
In user's home directory who will run drush and ahs web privileges change permissions of .drush and drush-backups (created during install) for that user
sudo chown -R username:usergroup ~/.drush
sudo chown -R username:usergroup ~/drush-backups

grzesag’s picture

if you are running Ubuntu 13.04 you can install drush using apt-get but it installes drush version 5.8.

To upgrade to version drush 5.9 please do following:
sudo drush dl drush --destination='/usr/share/php'

Hope it helps someone

remerjohnson’s picture

I installed via apt-get method on Ubuntu 13.10. Install worked fine, but when executing drush version, I get:

PHP Fatal error:  Call to undefined function json_encode() in /usr/share/php/drush/includes/output.inc on line 708
Drush command terminated abnormally due to an unrecoverable error.                                [error]
Error: Call to undefined function json_encode() in /usr/share/php/drush/includes/output.inc, line
708

I went to that json_encode() function and found the following:

/**
 * Converts a PHP variable into its Javascript equivalent.
 *
 * We provide a copy of D7's drupal_json_encode since this function is
 * unavailable on earlier versions of Drupal.
 *
 * @see drupal_json_decode()
 * @ingroup php_wrappers
 */
function drush_json_encode($var) {
  // json_encode() does not escape <, > and &, so we do it with str_replace().
  return str_replace(array('<', '>', '&'), array('\u003c', '\u003e', '\u0026'), json_encode($var));
}

Any thoughts on what to edit?

couloir007’s picture

I'm having the same problem.

alfonsojosegarcia’s picture

I too, any solution? Help!!

amitsedaiz’s picture

Installing the package separately will do the trick.
For Ubuntu: sudo apt-get install php5-json
Link: http://stackoverflow.com/questions/18239405/php-fatal-error-call-to-unde...

andykisaragi’s picture

Anyone like me currently getting this error when trying to install with PEAR:

Array to string conversion in /usr/share/php/PEAR/REST/13.php on line 80

This is due to a bug in drush: https://github.com/drush-ops/drush/issues/465

pavithra.raman’s picture

I had issues in installing drush via PEAR, but it looks like the pear channel is not maintained or has a bug.
More in the discussion on the github repo for drush
https://github.com/drush-ops/drush/issues/465

Copying the instructions to install drush via github below

Install composer and drush (debian but should be the same for most linux's)

Note: directories are up to you This was mine ...

clone git somewhere
git clone https://github.com/drush-ops/drush.git /usr/local/drush

create a link to drush from the bin dir
ln -s /usr/local/drush /usr/local/bin/drush

install composer
curl -sS https://getcomposer.org/installer | php

move it into the path and rename it
mv composer.phar /usr/local/bin/composer
(or you can link it like with drush above)

get dependencies
cd /usr/local/drush
composer install

You should be ready to go
Please add to this instruction with anything required for your own OS

pavithra.raman’s picture

They have updated the PEAR channel. It should work now.

leolandotan’s picture

I'm using Ubuntu 12.04. I have installed php-pear already but when i issue

pear channel-discover pear.drush.org

I get this error:
could not create lock file: fopen(/usr/share/php/.lock): failed to open stream: Permission denied

How can I fix this?

Thanks

leolandotan’s picture

I just issued the commands with "sudo".

ernestto’s picture

I try to use pear channel-discover pear.drush.org but not work I install drush with apt-get commands

rmfranciacastillo’s picture

Thank you! This has been very helpful! Just using:

sudo apt-get install drush

I was able to install drush in Ubuntu 14.04.
Cheers!

mralexho’s picture

Run the following command -

drush pm-download --select --all drush

Choose one of the available releases for drush:
 [0]   :  Cancel                                                
 [1]   :  7.x-5.x-dev            -  2013-Sep-30  -  Development 
 [2]   :  7.x-5.9                -  2013-Apr-17  -              
 [3]   :  7.x-5.8                -  2012-Nov-12  -              
 [4]   :  7.x-5.7                -  2012-Aug-18  -              
 [5]   :  7.x-5.6                -  2012-Aug-10  -              
...
...
...

Then select the release you'd like to download.

FlutterStack’s picture

I have installed drush several times but in ubuntu 14.04. I am getting error as below

/var/www/drupalenglish$ drush status
Drush needs to download a library from [error]
http://download.pear.php.net/package/Console_Table-1.1.3.tgz in order
to function, and the attempt to download this file automatically
failed because you do not have permission to write to the library
directory /usr/local/lib/php/drush/lib. To continue you will need to
manually download the package from
http://download.pear.php.net/package/Console_Table-1.1.3.tgz, extract
it, and copy the directory into your /usr/local/lib/php/drush/lib
directory.

johnhanley’s picture

Did you use sudo when installing drush?

Anonymous’s picture

Follow the instructions here. Its quite simple to install the latest drush. http://www.zyxware.com/articles/4497/drupal-installing-latest-version-of...

SivaprasadC’s picture

Thanks abhai_zyxware, nice Article. That worked for me!

kiwimind’s picture

When following the instructions above, please ensure that when adding the directory to your path that it's different than stated:

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

raphaelbluteau’s picture

Thanks kiwimind, that worked for me!

montag64’s picture

I already had drush installed (probably via pear and a digitalocean article circa 2015) and tried to update from 8.0.2 to 8.1.15. Anyway I installed the via composer globally without error and kept trying to run it but was getting 8.0.2 when typing drush --version. It was running drush from /usr/local/bin. Once I removed old drush manually and ran this...

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

...it started launching the new version.

Using Ubuntu 14.04 LTS with composer 1.5.2 and drush 8.0 to 8.1.15.

It seems like literally every two months there's a new package manager or dependency manager in linux. Why is this necessary? NPM? Brew? Pear? Composer? chocolatey? when will it end? We have reached a point of terminal silliness.

hiramanpatil’s picture

I had Drush 8 installed on the server. Received some errors while updating my Drupal site from version 8.3.3 to 8.4.0. so I have updated Drush to 9.0.0-beta8. Now drush commands are not working on the server. Everytime I execute Drush command it shows error messages like -

[Exception]
The pm-updatecode command was deprecated. Please see `composer outdated` and `composer update`.
For security release notification, see `drush pm:security`.

How can I downgrade Drush to previous version 8? Trying to unstalled Drush and install it again but PEAR or apt-get is not working. Not sure how Drush was installed on the server.

Current Drush version:-
Drush Commandline Tool version 9.0.0-beta8.

Help is appreciated.

Thanks,

adominique’s picture

I still can't upgrade above v 8.1.8.
Followed exact same procedure.
Almost same configuration Composer v 1.5.2, Ubuntu 14.04.2. and PHP 5.5.9 (is PHP version the problem?)

Stuck to Drush 8.1.8 on a Drupal 8.4.
This whole process is very annoying and I can't find a single and clear (and good) update explanation given by Drush or Drupal.

adominique’s picture

Finally made it manually like this (if it can help anybody):

download drush.phar v 8.1.15 from https://github.com/drush-ops/drush/releases;
copied to /Home;
removed current 'drush' from /usr/local/bin;
make downloaded 'drush.phar' executable: chmod +x drush.phar
moved drush.phar to /usr/local/bin: sudo mv drush.phar /usr/local/bin/drush

cgfx’s picture

Setting up a new server, and none of these things are working for me at all.

How can I install drush? I seem to have had no issues with composer, but it didn't seem to work.

Linux clockworkcorgi 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02) x86_64
$ php --version
PHP 7.0.27-0+deb9u1 (cli) (built: Jan 5 2018 13:51:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies

So:

root@clockworkcorgi:~# curl -sS https://getcomposer.org/installer | php
root@clockworkcorgi:~# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.6.3) successfully installed to: /root/composer.phar
Use it: php composer.phar

root@clockworkcorgi:~# mv composer.phar /usr/local/bin/composer
root@clockworkcorgi:~# composer global require drush/drush:7.*
Changed current directory to /root/.config/composer
Do not run Composer as root/super user! See https://getcomposer.org/root for details
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 7 installs, 0 updates, 0 removals
  - Installing symfony/yaml (v2.8.36): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.7.0): Downloading (100%)         
  - Installing symfony/var-dumper (v2.8.36): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing pear/console_table (v1.2.1): Downloading (100%)         
  - Installing d11wtq/boris (v1.0.10): Downloading (100%)         
  - Installing drush/drush (7.4.0): Downloading (100%)         
symfony/var-dumper suggests installing ext-symfony_debug ()
pear/console_table suggests installing pear/Console_Color2 (>=0.1.2)
Writing lock file
Generating autoload files

scott@clockworkcorgi:~$ composer global require drush/drush:7.*
Changed current directory to /home/scott/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 7 installs, 0 updates, 0 removals
  - Installing symfony/yaml (v2.8.36): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.7.0): Downloading (100%)         
  - Installing symfony/var-dumper (v2.8.36): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing pear/console_table (v1.2.1): Downloading (100%)         
  - Installing d11wtq/boris (v1.0.10): Downloading (100%)         
  - Installing drush/drush (7.4.0): Downloading (100%)         
symfony/var-dumper suggests installing ext-symfony_debug ()
pear/console_table suggests installing pear/Console_Color2 (>=0.1.2)
Writing lock file
Generating autoload files
scott@clockworkcorgi:~$ export PATH="$HOME/.config/composer/vendor/bin:$PATH"

But then:

scott@clockworkcorgi:~$ drush --version
-bash: drush: command not found

Confused as exasperating, as usual. Anyone know what I need to do from here?

jlbrewster’s picture

@cgfx I feel your pain. I have actually been using composer for more than a year with no problems, but while setting up a new Ubuntu17.10 workstation, I was having this error, and it wound up being a composer PATH issue in .bashrc:

What I had was:
export PATH="$HOME:/.composer/vendor/bin:$PATH"
I changed it to:
export PATH="~/.composer/vendor/bin:$PATH"
and that's what did it.

(I had to remind myself that .bashrc is what programs/applications use(not Cli) so if everything seems fine, but the program doesn't produce the correct output, that must be the culprit (my thinking)).

I'll bet it's a path issue in your case because I was having the same behavior: composer checked out with gold stars, but drush or any composer module was giving the "can't find ___" response). (Of course, since Composer was passing diagnostics, I wasn't looking there for the answer). Anyhow, post back if not, and I will try my best to lend my experience (I would hate for you to live life composer-less)..

I also found this resource to be quite helpful (a lot of varying "how-to's" around..):
http://docs.drush.org/en/8.x/install-alternative/

rex.barkdoll’s picture

Hi all,

I'm on Ubuntu 20.04, installed composer and drush, couldn't figure out where it was because the paths I kept adding weren't working out.

finally I found it in
export PATH="$HOME/.config/composer/vendor/drush/drush:$PATH"

Hope this helps someone out there.