# (Superseded) Develop In A Windows Environment Using Vagrant

**URL:** <https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386>\
**Category:** Development\
**Tags:** how-to\
**Created:** [October 4, 2017, 7:57am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386 "2017-10-04T07:57:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Tian](https://avatars.discourse-cdn.com/v4/letter/d/b487fb/32.png) [@Daniel\_Tian](https://meta.discourse.org/u/Daniel_Tian)\
**Post date:** [October 4, 2017, 7:57am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/1 "2017-10-04T07:57:36Z")

</div>

> ℹ This document is no longer maintained. See this topic instead: [Install Discourse on Windows for development](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-windows-10-for-development/75149)

# How To Develop In A Windows Environment Using Vagrant

This guide covers how to set up a Windows environment for Discourse development using Vagrant. By the end of the guide, you should have:

1. A Vagrant instance set up with Discourse running.
2. `rsync` running so that Discourse rebuilds the project whenever a file changes.
3. Cygwin terminals running Discourse and `rsync`.
4. Ability to view Discourse at [http://localhost:4000](http://localhost:4000) with live reloading of changes.

> **NOTE:** Discourse uses Ruby gems that depends on Linux system calls. Because of this, you must run Discourse in a full Linux environment; a POSIX environment like Cygwin or Git Bash is not enough. We use Vagrant to give us a fully-configured Linux virtual machine so that we don’t have to set it up by hand.
> 
> By default, Vagrant uses VirtualBox’s shared folders with the VM. However, this is [very slow](https://meta.discourse.org/t/development-mode-super-slow/2179). We will use `rsync` instead, which gives us all the features we need (file change events, symlinking support, and very fast performance). The only dependency is `Cygwin`, which we use to download `rsync`.

## Requirements

1. Windows 7 or higher
2. [VirtualBox](https://www.virtualbox.org/wiki/Downloads) - virtualization software that Vagrant uses
3. [Vagrant 64-bit](https://www.vagrantup.com/downloads.html) - sets up a pre-configured Ubuntu VM to run Discourse in
4. [Cygwin 64-bit](https://cygwin.com/install.html) - needed to download and run `rsync` and SSH into the Vagrant VM.

## Table Of Contents

- [Step 1: Install Required Software](#heading--step-1)
- [Step 2: Set Up And Start Vagrant](#heading--step-2)
- [Step 3: SSH Into Vagrant Box And Set Up Discourse](#heading--step-3)
- [Step 4: Start The Discourse Server](#heading--step-4)
- [Step 5: Restarting The Discourse Server After A Reboot](#heading--step-5)
- [Step 6: Troubleshooting](#heading--step-6)

## Step 1: Install Required Software

1. Download and install [VirtualBox](https://www.virtualbox.org/wiki/Downloads) with the default options.

2. Download and install [Vagrant 64-bit](https://www.vagrantup.com/downloads.html) with the default options. You will be asked to reboot after the installation is complete. A reboot is not necessary, but you can do it if you like.

3. Download and install [Cygwin 64-bit](https://cygwin.com/install.html). Keep clicking `Next` with the default options until you reach the `Select Packages` page:

 ![cygwin1](https://global.discourse-cdn.com/meta/original/3X/e/c/ec45c0e2270ee7934bc9c0e6b2dd525dd6169a57.png)

1. Change the `View` dropdown to `Full`, then search for `openssh`. Find the entry with the package `openssh: The OpenSSH server and client programs`, then click on the word `Skip` for that entry until it changes to a version number and the `Bin?` checkbox is checked:

 ![cygwin2](https://global.discourse-cdn.com/meta/original/3X/1/d/1d2c7643607bd7d4b11621a1de6814afcdc303b1.png)

1. Repeat the above step for `rsync`. The entry we want is `rsync: Fast remote file transfer program`:

 ![cygwin3](https://global.discourse-cdn.com/meta/original/3X/7/8/780a39d3909bf5d02f87e250d51c46dc00d0bf37.png)

1. Click `Next` and keep going through the installer with the default options until the Cygwin install is finished.

2. We now need to add VirtualBox to the system path so that Vagrant can use it. In Windows, search for `environment variables` in the start menu and click on `Edit the system environment variables`:

 ![systempath1](https://global.discourse-cdn.com/meta/original/3X/e/8/e83e78a58b6af2ceaa01b60dcb88c9fb19857a96.png)

1. In the dialog that pops up, click on the `Environment Variables` button on the lower right:

 ![systempath2](https://global.discourse-cdn.com/meta/original/3X/b/1/b16590879d86848d958802b90416982e401d9ef3.png)

1. A new dialog will display. In the lower `System variables` list, find the entry for `Path`, click on it, then click on the `Edit...` button:

 ![systempath3](https://global.discourse-cdn.com/meta/original/3X/8/3/83c2acadf6c0fdf3578714acc48dcb6e7c7a5211.png)

1. A third dialog will show. Click on the `New` button on the upper right, then type in `C:\Program Files\Oracle\VirtualBox` (this is where VirtualBox is installed by default; if you changed the install location, you need to use the location that you installed it to):

 ![systempath4](https://global.discourse-cdn.com/meta/original/3X/4/d/4d8891487eb642f7143406d5e27ff597237eea69.png)

> **NOTE:** If you are using Windows 8 or below, this dialog will look different. It will have a textbox for `Variable name` and `Variable value`. In this case, add `;C:\Program Files\Oracle\VirtualBox` to the end of the `Variable value` textbox.

1. Click `OK` for all 3 dialogs to close them all.

You have now installed all the required software and are ready to start up the Vagrant server.

## Step 2: Set Up And Start Vagrant

1. Clone a copy of Discourse from their [GitHub repo](https://github.com/discourse/discourse) into a local folder on Windows:

 ![configure1](https://global.discourse-cdn.com/meta/original/3X/0/1/0105c7c6bf4b1a48d72ca8a5f97651ff1cfae776.png)

1. In the Discourse folder, open the file `Vagrantfile` and find the following line:

```plaintext
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root"

```

Change it to:

```plaintext
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", type: "rsync",
  rsync__exclude: [".git/", "tmp/", "public/plugins/"]

```

 ![rsync](https://global.discourse-cdn.com/meta/original/3X/0/0/0089cf7f44e1683209accdf3362b5eb4ce02e0fb.png)

> **NOTE: DO NOT** commit this edit back to Discourse, it is a Windows-specific setting that will likely break things for users on OSX and Linux. We need to exclude the `tmp/` and `public/plugins/` folders because Discourse generates files into these folders on the Linux side, and we don’t want rsync to replace them with the empty folders on the Windows side.

1. Run `Cygwin64 Terminal`. It will open up a new terminal that looks very similar to the command prompt:

 ![configure3](https://global.discourse-cdn.com/meta/original/3X/4/3/4379ab463f32a9db0d699eb5dc709daebb700e07.png)

1. Using Cygwin, `cd` to the folder where you cloned Discourse into. To access the Windows `C:\` drive in Cygwin, use the path `/cygdrive/c`. In this guide, we installed Discourse to `C:\Projects\discourse`, so the command is:

```bash
cd /cygdrive/c/Projects/discourse

```

 ![configure4](https://global.discourse-cdn.com/meta/original/3X/5/b/5ba27a34882e07fa16ec3232db3d3c000cc31d67.png)

1. Type the following command to start the Vagrant server:

```plaintext
vagrant up

```

It will take some time to complete. You may be prompted several times by UAC for `VirtualBox Interface`. Make sure you click `Yes` each time.

1. You will eventually get the error message `Could not get lock /var/lib/dpkg/lock - open`:

 ![commandprompt6](https://global.discourse-cdn.com/meta/original/3X/0/8/083a41ef151cce110b63ee9c975767df24319aaa.png)

When this happens, run `vagrant reload`. You will notice it installing the VirtualBox Guest Additions this time:

 ![commandprompt7](https://global.discourse-cdn.com/meta/original/3X/a/8/a8ebc6ac5e456936300cf66ec5bf60c3e18f8679.png)

Once it completes, you will have a Vagrant instance created and running!

## Step 3: SSH Into Vagrant Box And Set Up Discourse

1. In a `Cygwin64 Terminal`, `cd` over to the Discourse folder and run the following command to `ssh` into the Vagrant VM:

```plaintext
vagrant ssh

```

 ![discourse-setup1](https://global.discourse-cdn.com/meta/original/3X/5/d/5d4a3fe14ba81aa8e8a470250967d08879d977cd.png)

1. `cd` over to `/vagrant`, which is where the Discourse shared folder is mounted, and run `bundle install` to install all the gems that Discourse needs. Sit back and relax, the install will take a while:

```plaintext
cd /vagrant
bundle install

```

 ![discourse-setup2](https://global.discourse-cdn.com/meta/original/3X/2/9/290504d44c3489b55dfe4496fccb10b08f565426.png)

1. Once all the gems are finished installing, run `rake db:migrate`:

```plaintext
rake db:migrate

```

 ![discourse-setup3](https://global.discourse-cdn.com/meta/original/3X/4/7/476feafe877c824d0083dd052390c9821e98f956.png)

1. Run `rake admin:create` to create an admin account. This is the account you will use to log into Discourse with. `Do you want to grant Admin privileges to this account?` Type `y`:

```plaintext
rake admin:create

```

 ![discourse-setup4](https://global.discourse-cdn.com/meta/original/3X/3/f/3fcbca1a4610bc6b4ed95d9a560ba4b49b67b4d6.png)

You have finished setting up Discourse and are ready to start the Discourse server.

## Step 4: Start The Discourse Server

1. Open up a new `Cygwin64 Terminal` and `cd` over to the discourse folder:

 ![configure4](https://global.discourse-cdn.com/meta/original/3X/5/b/5ba27a34882e07fa16ec3232db3d3c000cc31d67.png)

1. Run `vagrant rsync-auto`. This will run continuously in the Cygwin terminal, monitoring the folder for any changes and syncing them to the Linux side:

```bash
vagrant rsync-auto

```

 ![discourse-run1](https://global.discourse-cdn.com/meta/original/3X/e/3/e33ab5e3901210967457a32979a87454d5d960d2.png)

> **NOTE:** Breaking out of `vagrant rsync-auto` **will not** stop it from running. You must kill all instances of the process `ruby.exe` in the Task Manager to actually stop it. You should do this every time you break out of it.

1. You should already have a terminal that’s already `ssh`’ed into the VM and `cd`’ed over to `/vagrant`. Run `rails s -b 0.0.0.0` to start up the Discourse web server:

```plaintext
rails s -b 0.0.0.0

```

 ![discourse-run2](https://global.discourse-cdn.com/meta/original/3X/7/1/71b59a59146ee1617be9a4b8b30de4f814764518.png)

1. In your browser, navigate to [http://localhost:4000](http://localhost:4000). It will take a while to load initially, but eventually you should see the Discourse home page:

 ![discourse-run3](https://global.discourse-cdn.com/meta/original/3X/2/a/2a908cc3a05a3eb7bbb811a98e7338b0ad3ed1e5.png)

1. Verify that `rsync` is working properly and causes Discourse to do a live reload when a file changes. In your text editor, open the `app/assets/stylesheets/common/components/button.scss` file that’s in the Discourse folder. Add the style `background-color: red;` to the `.btn-small` class near the bottom of the file:

 ![discourse-run4](https://global.discourse-cdn.com/meta/original/3X/7/6/76ed87e67c4e34e1801a0efd302a627101925617.png)

1. Save the file and go back to your browser. In a few seconds, you should see the `Sign Up` and `Log In` buttons turn red:

 ![discourse-run5](https://global.discourse-cdn.com/meta/original/3X/f/3/f3d34b5be0ee0f852f87cc1cc5ef33cb2b33c887.png)

1. Undo the change to `buttons.scss` and save the file again. Go back to the browser, and after a few seconds the `Sign Up` and `Log In` buttons should turn back to blue.

2. Log in with the admin account that you created:

 ![discourse-run6](https://global.discourse-cdn.com/meta/original/3X/5/b/5bed159e150889614eae503ad766dbb6858376c6.png)

 ![discourse-run7](https://global.discourse-cdn.com/meta/original/3X/f/e/fe2e9f4df0459327d47a56a3dbfe9eaa349c6d33.png)

Congratulations, you are now ready for Discourse development!

## Step 5: Restarting The Discourse Server After A Reboot

Vagrant, the Discourse server, and `rsync` need to be restarted every time you reboot your development machine. To do so, open up two `Cygwin64 Terminals`. In the first terminal, run the following commands:

```plaintext
cd c:\Projects\discourse
vagrant up
vagrant ssh
cd /vagrant
rails s -b 0.0.0.0

```

In the second terminal, run the following commands:

```bash
cd /cygdrive/c/Projects/discourse
vagrant rsync-auto

```

Then open your browser to [http://localhost:4000](http://localhost:4000) and you should see the Discourse homepage.

## Step 6: Troubleshooting

1. If Vagrant is giving you error messages when you run `vagrant up`, check that the VM is not already running. Open `Task Manager`, click on the `Details` tab, and look for the `VBoxHeadless.exe` process. If it’s running, end all of them and retry `vagrant up`:

 ![taskmanager](https://global.discourse-cdn.com/meta/original/3X/7/1/715e4c83bb73316f6eaf2a238207a541f61a2da4.png)

1. Breaking `vagrant rsync-auto` will not stop it; it will continue running in the background. This can cause issues if you run the command multiple times. In order to stop it, open `Task Manager`, click on the `Details` tab, and end all instances of `ruby.exe` before running `vagrant rsync-auto`:

 ![rubyprocess](https://global.discourse-cdn.com/meta/original/3X/7/0/70105e36b4a80a17f9c0bb7afc38f859dcdc6425.png)

> **NOTE:** You should do this every time you break out of `vagrant rsync-auto`. Otherwise you can have multiple instances of `rsync-auto` running at the same time, which will cause issues.

---

<div class="post-metadata">

**Author:** ![obiwankenoobi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/obiwankenoobi/32/87493_2.png) [@obiwankenoobi](https://meta.discourse.org/u/obiwankenoobi)\
**Post date:** [January 16, 2018, 6:00am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/2 "2018-01-16T06:00:51Z")

</div>

Hello , Im new here and not sure this is the place to write it but, Im trying this tutorial and when I getting to the `vagrant ssh` part my cygwin terminal just stuck. What can I do?

---

<div class="post-metadata">

**Author:** ![GregIven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gregiven/32/89672_2.png) [@GregIven](https://meta.discourse.org/u/GregIven)\
**Post date:** [March 1, 2018, 10:49pm UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/3 "2018-03-01T22:49:01Z")

</div>

Step 4, part 2 is giving me this error:

> $ vagrant rsync-auto  
> ==\> default: Not syncing C:/Users/gdrew/Discourse/discourse as it is not part of the current working \>directory.  
> ==\> default: Doing an initial rsync…  
> There are no paths to watch! This is either because you have no  
> synced folders using rsync, or any rsync synced folders you have  
> have specified `rsync_auto` to be false.

Any ideas?

EDIT:

I found out the issue was where I located my discourse folder. The folder has to be placed in the same directory as rsync.exe. For me, using cygwin it was the cygwin64.

This is what the path looks like for reference:  
C:\cygwin64\home[YOUR-COMPUTER-NAME-HERE]\vagrant\discourse

---

<div class="post-metadata">

**Author:** ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)\
**Post date:** [June 8, 2018, 12:24am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/4 "2018-06-08T00:24:41Z")

</div>

I’ve cloned discourse and there is no Vagrantfile in the root folder [GitHub - discourse/discourse: A platform for community discussion. Free, open, simple. · GitHub](https://github.com/discourse/discourse)

Should I use the one from here?

> <https://github.com/discourse/discourse/blob/v1.9.0.beta17/Vagrantfile>

---

<div class="post-metadata">

**Author:** ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)\
**Post date:** [June 8, 2018, 12:29am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/5 "2018-06-08T00:29:49Z")

</div>

I believe this whole thing is deprecated @sam? Shouldn’t Docker on Windows be used instead?

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [June 8, 2018, 12:34am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/6 "2018-06-08T00:34:59Z")

</div>

Yes Docker on Windows OR Linux Subsystem for Windows OR a VM is what you want for Windows dev.

Docker on Windows is probably easiest.

---

<div class="post-metadata">

**Author:** ![sarahann](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sarahann/32/96703_2.png) [@sarahann](https://meta.discourse.org/u/sarahann)\
**Post date:** [June 8, 2018, 12:40am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/7 "2018-06-08T00:40:00Z")

</div>

Darn! I was mostly through the instructions.

Thanks for the quick replies! I’ll go find the docker setup 🙂

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [June 8, 2018, 1:12am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/8 "2018-06-08T01:12:32Z")

</div>



---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [June 8, 2018, 1:12am UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/9 "2018-06-08T01:12:34Z")

</div>



---

<div class="post-metadata">

**Author:** ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)\
**Post date:** [September 23, 2022, 2:14pm UTC](https://meta.discourse.org/t/superseded-develop-in-a-windows-environment-using-vagrant/71386/10 "2022-09-23T14:14:26Z")

</div>


