Submitted by jeanseb on Tue, 12/18/2018 - 11:10

Pour installer drush avec composer rien de plus simple.

Tout d'abords, si vous n'avez pas composer il faut l'installer.
Sous ubuntu on fait ça avec la commande suivante :

sudo apt install composer

Ensuite pour l'installation je suggère de placer dans /usr/share/drush .

Il faut créer les répertoire et se donner les droits nécessaire.

sudo mkdir /usr/share/drush
sudo chgrp www-data /usr/share/drush
sudo chmod g+w /usr/share/drush

Étant donné qu'il est déconseiller d'exécuter composer en tant que root, j'ai choisi  de donner les droits au groupe www-data parce que ça concerne le site web.
Vous pouvez utiliser le groupe de votre user, mais si vous voulez faire pareil n'oubliez pas de vous ajouter au groupe www-data (et de vous déconnecter pour que ce soit pris en compte) :

addgroup moi www-data

 

Ensuite il faut faire l'installation :

cd /usr/share/drush
composer require drupal/drush

pour vérifier on le lance avec 

/usr/share/drush/vendor/bin/drush 

et on obtient :

Drush Commandline Tool 9.5.2

Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more documentation.

 Available commands:                                                                                                
 _global:                                                                                                           
   help                                 Display usage details for a command.                                        
   list                                 List available commands.                                                    
   runserver (rs, serve)                Runs PHP's built-in http server for development.                            
   updatedb (updb)                      Apply any database updates required (as with running update.php).           
   version                              Show Drush version.                                                         
   browse                               Display a link to a given path or open link in a browser.                   
   generate (gen)                       Generate boilerplate code for modules/plugins/services etc.                 
   user:login (uli)                     Display a one time login link for user ID 1, or another user.               
   drupal:directory (dd)                Return the filesystem path for modules/themes and other key folders.        
   entity:updates (entup)               Apply pending entity schema updates.                                        
   updatedb:status (updbst)             List any pending database updates.                                          
   config:pull (cpull)                  Export and transfer config from one environment to another.                 
   pm:security (sec)                    Check Drupal Composer packages for pending security updates.                
 cache:                                                                                                             
   cache:get (cg)                       Fetch a cached object and display it.                                       
   cache:clear (cc)                     Clear a specific cache, or all Drupal caches.                               
   cache:set (cs)                       Cache an object expressed in JSON or var_export() format.                   
   cache:rebuild (cr, rebuild)          Rebuild a Drupal 8 site.                                                    
 core:                                                                                                              
   core:rsync (rsync)                   Rsync Drupal code or files to/from another server using ssh.                
   core:status (status, st)             An overview of the environment - Drush and Drupal.                          
   core:edit (conf, config)             Edit drushrc, site alias, and Drupal settings.php files.                    
   core:init (init)                     Enrich the bash startup file with bash aliases and a smart command prompt.  
   core:topic (topic)                   Read detailed documentation on a given topic.                               
   core:execute (exec, execute)         Execute a shell command. Usually used with a site alias.                    
 php:                                                                                                               
   php:eval (eval, ev)                  Evaluate arbitrary php code after bootstrapping Drupal (if available).      
   php:script (scr)                     Run php a script after a full Drupal bootstrap.                             
 site:                                                                                                              
   site:ssh (ssh)                       Connect to a Drupal site's server via SSH.                                  
   site:install (si, sin)               Install Drupal along with modules/themes/configuration/profile.             
   site:set (use)                       Set a site alias that will persist for the current session.                 
   site:alias (sa)                      Show site alias details, or a list of available site aliases.               
   site:alias-convert (sa-convert, sac) Convert legacy site alias files to the new yml format.                      
 sql:                                                                                                               
   sql:sync                             Copy DB data from a source site to a target site. Transfers data via rsync. 
   sql:connect                          A string for connecting to the DB.                                          
   sql:create                           Create a database.                                                          
   sql:drop                             Drop all tables in a given database.                                        
   sql:cli (sqlc)                       Open a SQL command-line interface using Drupal's credentials.               
   sql:query (sqlq)                     Execute a query against a database.                                         
   sql:dump                             Exports the Drupal DB as SQL using mysqldump or equivalent.                 

 ! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands.

 

La dernière étape consiste a faire un lien symbolique dans /usr/local/bin pour pouvoir le lancer simplement :

sudo ln -s /usr/share/drush/vendor/bin/drush /usr/local/bin/

Vous pouvez revérifier en tapant simplement " drush " dans votre terminal vous devez avoir la même sortie que précédemment.