# Configurar um ambiente de desenvolvimento usando Vagrant no Ubuntu

**URL:** https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277
**Category:** Development
**Tags:** how-to
**Created:** [Junho 5, 2016, 2:54pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277 "2016-06-05T14:54:07Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Junho 5, 2016, 2:54pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/1 "2016-06-05T14:54:07Z")

</div>

> ℹ This doc is no longer maintained and using Docker for development is recommended instead of using Vagrant. See: [Install Discourse for development using Docker](https://meta.discourse.org/t/beginners-guide-to-install-discourse-for-development-using-docker/102009)

After having setup several systems with a discourse development environment using Vagrant, I thought I would write a quick guide here, which I really should submit as a README. This setup was tested on a virgin installation of 18.04, and uses Eclipse with Aptana Studio 3.

1. Install requirements  
`sudo apt install vagrant virtualbox virtualbox-dkms git`

- Follow [these directions](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/) to also generate a new ssh key and add it to the ssh agent, then [add to your github settings](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account). ([Thank you](https://meta.discourse.org/t/howto-set-up-a-development-environment-using-vagrant-ubuntu-guide/45277/14) @tobiaseigen)

1. Get Discourse source

```mkdir
cd ~/workspace
git clone git@github.com:discourse/discourse.git
# git clone https://github.com/discourse/discourse.git # If you prefer HTTPS

```

1. Merge Vagrantfile

```plaintext
cd discourse
git remote add vagrant-tarek git@github.com:tareko/discourse.git
git merge vagrant-tarek/master

```

1. Start machine  
`vagrant up`

2. Enter VM  
`vagrant ssh`

3. Go to Relevant directory  
`cd /vagrant`

4. Finish setup of environment

```plaintext
bundle install
bundle exec rake db:create db:migrate db:test:prepare

```

1. Create an admin account

```plaintext
cd /vagrant
rake admin:create

```

1. Start Server. NOTE: You will need to execute all three of these commands every time!  
`cd ~/`  
`mailcatcher --ip 0.0.0.0`  
`cd /vagrant`  
`bundle exec rails s -b 0.0.0.0 `  
`bundle exec sidekiq -l log/sidekiq.log -q critical -q default -q low`

- Note: If you make changes in your code, please Ctrl-C both the rails server and sidekiq.
- Note: You’ll need two consoles to run both sidekiq and the rails server.

1. Point your browser to:  
[http://127.0.0.1:4000](http://127.0.0.1:4000) - Discourse instance  
[http://127.0.0.1:4000/sidekiq](http://127.0.0.1:4000/sidekiq) - Sidekiq queues  
[http://127.0.0.1:4080](http://127.0.0.1:4080) - mailcatcher

2. _Optional_ Install Eclipse, egit and Aptana

- Get eclipse from [Eclipse Downloads | The Eclipse Foundation](http://www.eclipse.org/downloads/) - I usually get Eclipse for PHP developers
- Add egit by adding the following repository to eclipse: [Eclipse software repository | The Eclipse Foundation](http://download.eclipse.org/egit/updates)
- Add Aptana Studio by adding the following repository to Eclipse: [http://download.aptana.com/studio3/plugin/install](http://download.aptana.com/studio3/plugin/install)

## Creating a vagrant box:

These instructions are only for use if you are creating a vagrant box if this one goes bad.

1. Get a generic vagrant box from [Vagrant cloud](https://app.vagrantup.com/boxes/search). In this case, I used generic/ubuntu1804

2. Use that box in the `Vagrantfile` for now

3. Start the vagrant instance with `vagrant up` then enter with `vagrant ssh`

4. Update with `sudo apt update; sudo apt upgrade`  
a. Add VBox guest additions: `sudo apt install virtualbox-guest-dkms virtualbox-guest-utils`  
b. Add ipv6 [as per this bug report](https://stackoverflow.com/questions/50668845/cannot-install-redis-server-on-ubuntu-18-04#50669018).

5. Set locale appropriately: `localedef -v -c -i en_US -f UTF-8 en_US.UTF-8`. Do this before installing postgresql or else you’ll have to delete and recreate the cluster.

6. Run the [Install Discourse on Ubuntu or Debian for Development](https://meta.discourse.org/t/beginners-guide-to-install-discourse-on-ubuntu-for-development/14727).

7. Create postgresql user [as per these instructions](https://stackoverflow.com/posts/23934693/revisions) and give them `createdb` privileges [as per here](https://www.postgresql.org/message-id/463B31D5.8040308%40archonet.com).

8. Export box

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Junho 5, 2016, 7:02pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/2 "2016-06-05T19:02:03Z")

</div>

> [@tarek](#):
>
> Start Server. NOTE: You will need to execute all three of these commands every time!

Should we update this screen definition? So that starting all three items becomes as simple as `screen -m -c vagrant.screen`  
[https://github.com/discourse/discourse/blob/master/docs/vagrant.screen](https://github.com/discourse/discourse/blob/master/docs/vagrant.screen)

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [Junho 5, 2016, 7:16pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/3 "2016-06-05T19:16:17Z")

</div>

Small issue I ran into: mailcatcher couldn’t be started from `/vagrant`, needed to return to home directory in order to run it.

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Junho 5, 2016, 7:34pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/4 "2016-06-05T19:34:14Z")

</div>

> [@jomaxro](#):
>
> Small issue I ran into: mailcatcher couldn’t be started from /vagrant, needed to return to home directory in order to run it.

I updated the instructions.

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Junho 5, 2016, 7:35pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/5 "2016-06-05T19:35:09Z")

</div>

> [@cpradio](#):
>
> Should we update this screen definition? So that starting all three items becomes as simple as screen -m -c vagrant.screen

Would you believe that’s the first I see this.. I don’t have enough experience with screen to comment, so obviously change if necessary. I did notice that sidekiq without -q default -q low -q critical does not execute all queues for some reason.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [Junho 5, 2016, 7:35pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/6 "2016-06-05T19:35:56Z")

</div>

One more minor issue: these instructions leave you without any accounts, and thus no Admin accounts either. While the instance provides a link to creating an Admin account, should it be included here?

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Junho 5, 2016, 7:40pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/7 "2016-06-05T19:40:45Z")

</div>

> [@jomaxro](#):
>
> One more minor issue: these instructions leave you without any accounts, and thus no Admin accounts either.

Thank you. I added it as step #7.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Junho 5, 2016, 7:43pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/8 "2016-06-05T19:43:00Z")

</div>

> [@tarek](#):
>
> Would you believe that’s the first I see this.. I don’t have enough experience with screen to comment, so obviously change if necessary.

We can continue to massage it as issues arise, but I think this would be a good start. Might be able to even call this automatically via `vagrant up`? Not sure if that is a good idea or not.

[https://github.com/discourse/discourse/pull/4251](https://github.com/discourse/discourse/pull/4251)

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [Junho 5, 2016, 7:43pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/9 "2016-06-05T19:43:04Z")

</div>

Looks like #8 formatting was affected…

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Junho 5, 2016, 7:47pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/10 "2016-06-05T19:47:12Z")

</div>

> [@jomaxro](#):
>
> Looks like #8 formatting was affected…

OK, fixed it. Thank you.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [Junho 5, 2016, 8:00pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/11 "2016-06-05T20:00:09Z")

</div>

Okay, so after running `vagrant ssh` you can now run `screen -m -c /vagrant/docs/vagrant.screen` to start up rails s, rails c, sideqik, mailcatcher, and a bash terminal

You can then use CTRL + a, " to cycle through the various terminals.

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [Julho 6, 2016, 1:16am UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/12 "2016-07-06T01:16:21Z")

</div>

So, at the end, do you edit code right in the `~/workspace/discourse` and get your running instance updated automatically instantly?

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Julho 8, 2016, 3:32am UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/13 "2016-07-08T03:32:16Z")

</div>

More or less..

You have to restart the sidekiq and rails s servers each time you make a change to the code.

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [Janeiro 16, 2017, 3:55pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/14 "2017-01-16T15:55:08Z")

</div>

Hi Tarek - thanks for sharing this howto. I really appreciate it. I’ve tried following your instructions and noticed there are a few interim steps that are required. These become obvious as you move along but I thought I’d share them for the benefit of those who follow (including most likely myself.. ;-)). I also found it helpful to review [this discourse blog post about discourse as your first rails app](https://blog.discourse.org/2013/04/discourse-as-your-first-rails-app/) while setting up virtualbox on my mac.

- after step 1, also install git as instructed when you try to clone the discourse repo.
- after installing git, [follow these directions](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/) to also generate a new ssh key and add it to the ssh agent, then [add to your github settings](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account).

This is a good news, bad news post. Where I get stuck is on step 3. It hangs and eventually times out. I know this is a virtualbox/vagrant issue or even a hardware issue, but I’d be grateful for any advice. Here’s as far as I have come -

I followed [these instructions](https://stackoverflow.com/questions/23293071/timed-out-while-waiting-for-the-machine-to-boot-when-vagrant-up) found on stack overflow to add some lines to Vagrantinfo file, to turn on the gui so I can see what’s causing the holdup:

```
config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

```

This is what I found:

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

I am puzzled because I have a newish 2015 macbook pro with retina display, and am fairly certain it supports hardware acceleration. Also not getting entirely why I’d need such a thing for a discourse dev box. Anyhoo, now off to try this on a different laptop…

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Janeiro 16, 2017, 6:10pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/15 "2017-01-16T18:10:11Z")

</div>

Hi Tobias,

Thank you for your comments. I’m not able to edit my first post for some reason (probably time), so unfortunately people will have to find your comments.

Regarding the virtualization, I know nothing of Apple devices, but usually that is turned ON in BIOS. Alternatively, you can turn off the setting (which would result in slower performance). Turn off the setting in System \> Acceleration here:

 ![](https://global.discourse-cdn.com/meta/original/3X/6/8/68500d7ad412469dc9842e57def4a1f11e347e74.png)

I did a few web searches and see there is some discussion about how to enable in Macbooks. I won’t post them here so as not to misguide without testing, but please do post when you get it.

Thank you : )

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [Janeiro 24, 2017, 5:55pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/16 "2017-01-24T17:55:16Z")

</div>

> [@tarek](#):
>
> I’m not able to edit my first post for some reason (probably time), so unfortunately people will have to find your comments.

I’ve wikified your topic so that you may update the OP with any new information that has come along 🙂

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Outubro 23, 2018, 3:02pm UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/17 "2018-10-23T15:02:28Z")

</div>

As noted in a few other places (that I can’t find at the moment), the Vagrantfile has been removed. Since I have to work on my plugin (replyto-individual), I will get this going again and submit another pull request. I will also update the first post as needed.

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Outubro 24, 2018, 3:35am UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/18 "2018-10-24T03:35:55Z")

</div>

I have updated the `Vagrantfile` so that it creates a proper machine with Ubuntu 18.04 and the most recent (2018-10-23) Discourse. I’ve submitted a pull request with the new `Vagrantfile` and the screen file in the docs.

@erlend_sh: Will you consider putting the vagrant file back into the main repository?

[https://github.com/discourse/discourse/pull/6524](https://github.com/discourse/discourse/pull/6524)

---

<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: [Outubro 24, 2018, 5:19am UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/19 "2018-10-24T05:19:48Z")

</div>

I appreciate this but we would need to take ownership of this image and maintenance, this is not a bite I want to chew.

Instead the recommendation is to use:

[https://github.com/discourse/discourse/tree/master/bin/docker](https://github.com/discourse/discourse/tree/master/bin/docker)

It is fast an easy.

---

<div class="post-metadata">

### Author: ![tarek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tarek/32/124831_2.png) [@tarek](https://meta.discourse.org/u/tarek)
#### Post date: [Outubro 24, 2018, 5:38am UTC](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277/20 "2018-10-24T05:38:01Z")

</div>

Thank you for this, @sam. I could easily make it so it uses a Vagrant stock image and then does the work I did in the image (it would use ansible). At that point, you can easily host a stock image that would take a few minutes to assemble.

Regarding development with docker, I don’t know how to do this, so I will take a look. I can’t speak to the main advantages of Vagrant vs. Docker for development, so perhaps others can.

[Next page](https://meta.discourse.org/t/superseded-set-up-a-development-environment-using-vagrant-on-ubuntud/45277.md?page=2)
