Drush 是一个命令行工具,可以很方便的安装和管理 Drupal,可是我在 Debian Jessie 上用 apt-get install drush 安装后,Drush 的版本却是可怜的 5.10.0,目前 Drush 已经有了 8.x 和 9.x,我们怎么可以去安装这些更高级的版本呢?

我们可以用 git clone 命令直接从 Drush 的 Github 库里面获取最新版本:

git clone https://github.com/drush-ops/drush.git

也可以去 Drush 过往版本的发布页面去选择自己想要的版本:https://github.com/drush-ops/drush/releases

我们把获取的 Drush 源码放入 /usr/local/src/drush 文件夹,然后进入这个文件夹,如果您操作的正确,应该可以看到 composer.json 等文件:

cd /usr/local/src/drush

执行 composer install 去安装 Drush,composer 会自动安装 Drush 所依赖的东西:

composer install

如果返回的都是像下面一样100%和 successfully 等字样而没有报错,表示安装正常:

Installing dependencies (including require-dev) from lock file
Package operations: 36 installs, 0 updates, 0 removals
  - Installing symfony/finder (v2.8.28): Downloading (100%)         
  - Installing symfony/event-dispatcher (v2.8.28): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.5.0): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing symfony/debug (v2.8.28): Downloading (100%)         
  - Installing symfony/console (v2.8.28): Downloading (100%)         
  - Installing phpdocumentor/reflection-docblock (2.0.5): Downloading (100%)         
  - Installing consolidation/output-formatters (3.1.11): Downloading (100%)         
  - Installing consolidation/annotated-command (2.7.2): Downloading (100%)         
  - Installing jakub-onderka/php-console-color (0.1): Downloading (100%)         
  - Installing pear/console_table (v1.3.0): Downloading (100%)         
  - Installing symfony/var-dumper (v2.8.28): Downloading (100%)         
  - Installing nikic/php-parser (v2.1.1): Downloading (100%)         
  - Installing jakub-onderka/php-console-highlighter (v0.3.2): Downloading (100%)         
  - Installing dnoegel/php-xdg-base-dir (0.1): Downloading (100%)         
  - Installing psy/psysh (v0.8.11): Downloading (100%)         
  - Installing webmozart/assert (1.2.0): Downloading (100%)         
  - Installing webmozart/path-util (2.3.0): Downloading (100%)         
  - Installing phpunit/php-token-stream (1.4.11): Downloading (100%)         
  - Installing symfony/yaml (v2.8.28): Downloading (100%)         
  - Installing sebastian/version (1.0.6): Downloading (100%)         
  - Installing sebastian/global-state (1.1.1): Downloading (100%)         
  - Installing sebastian/recursion-context (1.0.5): Downloading (100%)         
  - Installing sebastian/exporter (1.2.2): Downloading (100%)         
  - Installing sebastian/environment (1.3.8): Downloading (100%)         
  - Installing sebastian/diff (1.4.3): Downloading (100%)         
  - Installing sebastian/comparator (1.2.4): Downloading (100%)         
  - Installing phpunit/php-text-template (1.2.1): Downloading (100%)         
  - Installing doctrine/instantiator (1.0.5): Downloading (100%)         
  - Installing phpunit/phpunit-mock-objects (2.3.8): Downloading (100%)         
  - Installing phpunit/php-timer (1.0.9): Downloading (100%)         
  - Installing phpunit/php-file-iterator (1.4.2): Downloading (100%)         
  - Installing phpunit/php-code-coverage (2.2.4): Downloading (100%)         
  - Installing phpspec/prophecy (v1.7.2): Downloading (100%)         
  - Installing phpunit/phpunit (4.8.36): Downloading (100%)         
  - Installing symfony/process (v2.7.35): Downloading (100%)         
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/event-dispatcher suggests installing symfony/http-kernel ()
phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
pear/console_table suggests installing pear/Console_Color2 (>=0.1.2)
symfony/var-dumper suggests installing ext-symfony_debug ()
psy/psysh suggests installing ext-pdo-sqlite (The doc command requires SQLite to work.)
psy/psysh suggests installing hoa/console (A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit.)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Generating autoload files

成功以后,在环境变量的目录下面创建一个 drush 的快捷方式:

ln -s /usr/local/src/drush/drush /usr/bin/drush

意思就是为 /usr/local/src/drush/drush 创建一个快捷方式,放到 /usr/bin/drush  这里。现在你应该可以在系统的任何地方使用 drush 命令了:

drush help

然后我们查看一下 Drush 的版本:

drush --version

恭喜你,你应该用上更高版本的 Drush 了!