How to install Composer and Drush LOCALLY and GLOBALLY

Install Composer to your LOCAL user directory

cd ~
mkdir .composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar ~/bin/composer
chmod +x ~/bin/composer
echo "PATH=$PATH:~/.composer/vendor/bin" >> ~/.bash_profile
. ~/.bash_profile

Install latest version of Drush locally

Get the latest (or whatever) version here:

https://github.com/drush-ops/drush/releases

cd /LOCATION/OF/DRUPAL
composer require drush/drush

And we done...

DEPRECATED:

cd ~
mkdir bin
chmod +x bin
cd bin
wget https://github.com/drush-ops/drush/releases/download/[VERSION]/drush.phar
chmod +x drush.phar
mv drush.phar ~/bin/drush
# Following will further setup drush and add "~/.drush/" contents and update your "~/.bashrc"
# Backup .bashrc in case something goes wrong and then finish setting up drush.
cp .bashrc .bashrc-bak 
drush init

Now lets reload our .bashrc and check the drush version:

. ~/.bashrc
# which is same as:
# source ~/.bashrc
​
​drush version

PREVIOUS METHOD:

cd ~
git clone https://github.com/drush-ops/drush.git drush
# or to install another version; example 8.x which is PHP 5.5 compatible
# git clone -b 8.x https://github.com/drush-ops/drush.git  
cd ~/drush
composer install

To update drush after install:

cd ~/drush
git pull https://github.com/drush-ops/drush.git master
composer update

Install latest version of Composer GLOBALLY 

mkdir /usr/local/share/composer
cd /usr/local/share/composer
curl -sS https://getcomposer.org/installer | php
cp -Rf composer.phar /usr/local/bin/composer

Install latest version of Drush globally

Get the latest (or whatever) version here:

https://github.com/drush-ops/drush/releases

mkdir /usr/local/src/drush
cd /usr/local/src/drush
wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/latest
# or if that doesn't work:
# wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar
chmod +x drush.phar
cp -Rf drush.phar /usr/local/bin/drush
cd /LOCATION/OF/DRUPAL
composer require drush/drush
 
<h4 type="bash"><strong>DEPRECATED:</strong></h4>
 
<pre type="bash">
cd /usr/local/share
yum install git   # install GIT if not available
git clone https://github.com/drush-ops/drush.git drush
cd drush
rm -rf /usr/local/bin/drush; ln -s /usr/local/share/drush/drush /usr/local/bin/drush

To update an existing drush git installation:

cd /usr/local/share/drush
git pull https://github.com/drush-ops/drush.git master
rm -rf /usr/local/bin/drush; ln -s /usr/local/share/drush/drush /usr/local/bin/drush
composer install
composer global update 

TROUBLESHOOTING

For Godaddy hosting, do the following (DEPRECATED: use local instructions above):

*** THIS MAY BE OUTDATED *** Use above local install instructions instead

cd ~
git clone https://github.com/drush-ops/drush.git drush
curl -sS https://getcomposer.org/installer | php
mv composer.phar composer
cd drush
composer install

To update an existing drush git installation

cd ~/drush
git pull https://github.com/drush-ops/drush.git master

Update your .bash_profile so it looks like this

# .bash_profile
 
 
#start drush #
 
export DRUSH_PHP="/usr/bin/php5"
 
export COLUMNS
 
alias drush="/usr/bin/php5 ~/drush/drush.php"
alias composer="/usr/bin/php5 ~/composer"
 
alias php="/usr/bin/php5"
 
# end drush # 
 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
 
# User specific environment and startup programs
 
PATH=$PATH:$HOME/bin
 
export PATH

Now let's test it.

drush

If all went well, last command 'drush' should bring up all the drush commands.

setup Drush aliases

Now we need to tell Drush where the new site will be located... Drush doesn't overwrite the original site, so we need to tell it where the DEV/TEMP location will be.

vi /usr/local/share/drush/aliases.drushrc.php

Paste this code into it (hit "i" on your keyboard to insert)

<?php
$aliases
['siteA'] = array(
  
'uri'  =&gt'localhost',
  
'root' =&gt'/home/siteA/public_html'// This must be a full full path, not a relative one
);

$aliases['siteB'] = array(
  
'uri'  =&gt'localhost',
  
'root' =&gt'/home/siteB/public_html'// This must be a full full path, not a relative one
);

$aliases['siteC'] = array(
  
'uri'  =&gt'localhost',
  
'root' =&gt'/home/siteC/public_html'// This must be a full full path, not a relative one
  
'db-url' =&gt'mysql://DBUSER:DBPASS@localhost/DBNAME'//this is your new DB that you will have to create before the upgrade
);

$aliases['allsites'] = array('site-list' =&gt; array('@siteA','@siteB','@siteC'),);?>

Example Usage

drush @siteA pm-update #This will update drupal and all modules on 'siteA' 
drush @allsites pm-update #This will update all sites under 'allsites' alias

See here for Drupal major version upgrades using drush.

Troubeshooting

"No Drupal site found, only 'drush' cache was cleared." can mean that you're unable to connect to the database. To confirm use the following command:

drush -v -d sql-cli

If you get an error message stating that "composer" is required, then you didnt' install composer correctly.

Unable to load autoload.php. Drush now requires Composer in order to install its depedencies and autoload classes. Please see README.md

If you get this error message :

git-remote-https: /usr/local/lib/libz.so.1: no version information available (required by git-remote-https)
git: /usr/local/lib/libz.so.1: no version information available (required by git)

You can fix with DirectAdmin's custombuild

cd /usr/local/directadmin/custombuild
./build update 
vi options.conf

Change the below settings to the following.

#versions of zlib, apr_util and libxml2 (experts only)
zlib=yes
new_zlib=yes
new_xml2=yes

Then do the following:

./build zlib; ./build libxml2; ./build php n

And that should fix it.

Tags: Drupal Administration Linux drush composer