Install Drush on Windows - The easy way.

Here are the complete steps you need to take:

  1. Install Cygwin
    1. Install ncurses package. You need to select ncurses manually in cygwin setup. If you miss to install this you will get an error message that tput is missing.
    2. Install Git package
    3. Install bsdtar package or you cannot restore archives and get errors like Unable to untar and Unable to extract site archive tarball.
    4. Install Curl package or you cannot disable modules.
  2. Now install Composer for Windows globally.
  3. Install Drush the common way. e.g. Drush 8.x (stable):
    composer global require drush/drush:8.*
    

NOTE: Drush cannot run with GnuWin32 as it has no sh.exe support.

NOTE: Drush 9 aka the "master" branch only works with Drupal 8.

Comments

rayvan’s picture

Although this is elaborated on the issue resolution - it should be clarified here also. The PATH environment variable should be assigned by going to My Computer > Right-click any blank area inside window > Properties > Advanced tab > Environment Variables > System Variables > select PATH & edit as described.

This instruction is for Windows XP SP3 32-bit.

Thank you,
Ivan

DanChadwick’s picture

On Windows 8.1, for reasons I don't understand, drush 6.0 installed fine via the windows installer and ran from the DOS command window, but would not run from the git bash window. Only the system path was recognized. I added the PHP path to the system path, and it work. I removed it (leaving it in the user path), and it still worked. Perhaps some odd caching??

tostinni’s picture

On windows XP, %* works and accept all arguments, so I'm not sure you need to put %1 %2..., although setting up this would limit you to 9 arguments...

silvis’s picture

Works on Windows 7 Home Premium 64-bit.

kantu’s picture

I tried this
drush dl cck
i get an alert saying libssl32.dll not found
It didnt work even after installin .dll file

najibx’s picture

A little variation that works for me.

1. Added path

;C:\Program Files (x86)\PHP;C:\inetpub\wwwroot\drush;C:\Program Files (x86)\GnuWin32\bin;C:\Program Files\MySQL\MySQL Server 5.1\bin

2. For drush.bat, keep the original. No need to change anything. Although as recommend to put the full path to php.

Drush ruless !

decibel.places’s picture

$ drush or $drush.bat both work on Windows
I was under the impression that I had to call drush.bat on Windows but drush works fine as an alias

thamas’s picture

When using xampp on windows you may get warnings like "PHP Startup: Unable to load dynamic library (...)".

In this case look at the php.ini file (since xampp 1.7.1 in the xampp\php folder see: http://www.apachefriends.org/en/faq-xampp-windows.html#phpini).

I had to change the line 'extension_dir = "\xampp\php\ext"' to 'extension_dir = "E:\xampp\php\ext"' and do the same for browscap.

kurkuma’s picture

If you download the zip versions of the binary packages, do not forget to download the dependencies as well.

decibel.places’s picture

Step 3

Using Xampp installed at c:\xampp the PATH to PHP is c:\xampp\php

Step 4

In drush.bat I had to change

@php.exe "%~dp0drush.php" %*

to

@php.exe "%~dp0drush.php" %1 %2 %3 %4 %5 %6 %7 %8 %9

samuraijack’s picture

Thanks for your help

carole’s picture

I had to create C:\tmp to avoid "Fail to open stream" errors.

askibinski’s picture

Got it working with above instructions and a minor tweak for the batch file:
http://drupal.org/node/506448#comment-4585172

succesfull on Win 7 Professional, 64bit, Acquia stack (6.20)

Albert Skibinski - Homepage

Ellen Dee’s picture

If using Git and Drush isn't finding it, add the path to Git/bin to your Path environment variable; e.g. ;c:\Program Files (x86)\Git\bin. Then restart whatever shell you're using (i.e. cygwin).

Maung Maung’s picture

This procedure also work on Windows 7 Professionals 64 bit.

My PATH C:\drush\;C:\Program Files (x86)\GnuWin32\bin;C:\xampp\php

Thanks

dudeshane01’s picture

Although it is mentioned in top line that this tutorial was updated 16th April, the very first line in installating the hard way, Drush download url has not been corrected.
Kindly update that to GITHUB from drupal.org https://github.com/drush-ops/drush

jumpthattb’s picture

:)

vishal.sirsodiya’s picture

Hi,

I have follow all steps but again show this error blow :-

The drush command 'status' could not be found, Run 'drush cache-clear drush' to clear the commandfile cache if you have installed new extensions. function and the attempt to download this file automatically failed.To continue you will need to download the 1.1.3 package from website

nanabrownee’s picture

For my windows 8 I used the exe file to install Drush. Then I set the path like cited above in
control panel>system and security>system>advanced system settings> environment variables
And it was done. Had a few issue with a step by step installation, but the exe did the trick!
Now it's working fine Apart from a migrate thing havent quite figured out yet, but I guess that's just me ;)

Rishi Kulshreshtha’s picture

If still you're getting this error on Windows 7, then you should add this in your "Environment Variables"
C:\ProgramData\Drush;D:\xampp\php

Since, my XAMPP is installed in D drive, hence I've used that accordingly.

AlejCerro’s picture

I'm making this comment in case anyone else runs into this issue.

After banging my head for a couple of days because I kept getting an error about pear/console_table I realized that the reason it was failing was that Composer had locked the Drush and console_table files at the requirements for Drush 7.

Uninstalling Drush ( via composer ) then installing Drush again loaded the proper dependencies and allowed me to update to v8.1.8

Hope this helps someone else

LasVegasFIT’s picture

Here is a short video of the steps I used in this thread and others + internet that helped me to install Drush for Windows 10:

https://www.youtube.com/watch?v=laYrXwmw95E

devad’s picture

composer global require drush/drush:8.*

D8.4+ sites need at least Drush 8.1.15, so if you have updated to D8.4 recently - update Drush version as well.

One detail... run Drush commands via cygwin terminal from site root folder. Running Drush commands via Windows command prompt doesn't work (for me at least).

---------------------------------------------------
Drupal developer. Available for new projects

Dubs’s picture

I had a whole heap of trouble trying to get drush to work with remote aliases, local aliases, rsync and sql-sync on Windows. I wrote blog over here about it - https://www.drupology.co.uk/blog/settings-drush-windows-pc.

Here's a copy of the post: -

The problem with Drush on Windows

Windows just isn't geared up to work with Drush out the box for things like site alises, sql-sync, rsync etc.

The Solution

Site aliases

Site alias commands involving SSH will fail on Windows because drush will use single quotes rather than double quotes. To solve this, you just need to add a os setting to the drush alias file like this: -

site:
  os: Windows

That's it. Now when the command is concatenated, it will know you are using Windows and use the double-quotes.

Next you'll need to add your local site alias if you plan to copy files or databases between sites. Documentation can found all over to do this. You'll need to put these into drush/sites/example.site.yml in your project's docroot, or you can put them in your home directory's site alias directory.

drush rsync on Windows

You will need to download and extract cwRsync from here - https://www.itefix.net/cwrsync. Now it doesn't work out the box. You'll have to add the path of wherever you extracted to into the windows path variables.

Next problem is (depending on your command line interpreter) rsync will see paths like c:/folder as a remote destination, so expect errors like this: -

"the source and destination cannot both be remote"

To resolve this problem, create a rsync.bat file in bin directory of wherever you extracted cwrsync to and put something like this into it: -

@echo off
SETLOCAL
SET CWRSYNCHOME=C:\cwrsync
SET HOME=c:\Users\your user\
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\bin;%PATH%
SET args=%*
set newargs=%args:C:/=/cygdrive/c/%
rsync.exe %newargs%

This simply replaces C:\ with a path that cwrsync recognises as a local path.

Now you should be able to rsync from and to your site's docroot like this: -

drush rsync @self:sites/default/files @site-alias:sites/default/files

drush sql-sync

Lastly to ensure sql-sync works you need to add the mysql path to your windows environmental variables. If you see any errors with rsych, refer to the section above to get that working first.

Conclusion

That's it I think. Reach out if you have any questions or problems getting drush to work in Windows.

P.S. It's always useful to know what's going on. Running drush with a -vvv argument dumps all sorts of useful info which can help debug and fix any issues you may be having.

chippyjacob’s picture