# "Cannot allocate memory" when upgrading

**URL:** https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029
**Category:** Self-hosting
**Tags:** server-resources
**Created:** [May 11, 2016, 4:23am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029 "2016-05-11T04:23:42Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 11, 2016, 4:23am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/1 "2016-05-11T04:23:42Z")

</div>

Hi,  
I just got a message on my new discourse forum to upgrade to the latest version. On proceeding to the installation (on the black console), i saw some error messages that i dont really remember about an older version. The forum is still up, but when i _again_ try to click “click here to upgrade”, it takes me to the [www.website.com/admin/upgrade](http://www.website.com/admin/upgrade) , which says everything is up to date, but [www.website.com/admin](http://www.website.com/admin) still says there are upgrades available.

Whats going on?  
Thanks

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 11, 2016, 2:31pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/2 "2016-05-11T14:31:42Z")

</div>

…a little help here, somebody?

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [May 11, 2016, 2:39pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/3 "2016-05-11T14:39:42Z")

</div>

I don’t think that’s alarming, a little cache issue or the server that needs a reboot.

Go into the console (or Putty), and enter this command `shutdown -r now`

---

<div class="post-metadata">

### Author: ![steko](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@steko](https://meta.discourse.org/u/steko)
#### Post date: [May 11, 2016, 3:46pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/4 "2016-05-11T15:46:39Z")

</div>

I don’t think rebooting is a solution or a recommended action for any problem with Discourse, especially if there’s been a problem with an upgrade.

The sensible action here is to move to the Discourse directory `cd /var/discourse` and rebuild the app from the command line with ` /launcher rebuild app`.

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 16, 2016, 1:22am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/5 "2016-05-16T01:22:31Z")

</div>

This is from the console that i get when trying to update -

> An error occurred while installing eventmachine (1.2.0.1), and Bundler cannot  
> continue.  
> Make sure that `gem install eventmachine -v '1.2.0.1'` succeeds before bundling.

Then i did a “apt-get install ruby” (as suggested by my system) - I don’t know why i had to install ruby at this point. Anyway, it went successful.

And then when i do -

> gem install eventmachine -v ‘1.2.0.1’

I get error “Error installing eventmachine. Failed to build gem native extension”

---

<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: [May 16, 2016, 1:27am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/6 "2016-05-16T01:27:11Z")

</div>

Try

```plaintext
cd /var/discourse
git pull
./launcher rebuild app

```

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 22, 2016, 2:37am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/7 "2016-05-22T02:37:40Z")

</div>

Tried, still getting errors… Following is the stuff copied from the command line that opens while updating from the admin panel.

```
***Please be patient, next steps might take a while***
 ********************************************************
$ bundle install --deployment --without test --without development
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Fetching dependency metadata from https://rubygems.org/
Using rake 10.5.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Installing mini_portile2 2.1.0
Installing pkg-config 1.1.7
Using rack 1.6.4
Using mime-types 2.99.1
Using arel 6.0.3
Using jmespath 1.1.3
Using babel-source 5.8.34
Using execjs 2.6.0
Using ember-source 1.12.2
Using byebug 8.2.1
Using certified 1.0.0
Using coderay 1.1.0
Using concurrent-ruby 1.0.2
Using connection_pool 2.2.0
Using crass 1.0.2
Using daemons 1.2.3
Using diff-lcs 1.2.5
Using thor 0.19.1
Using discourse_fastimage 2.0.0
Using docile 1.1.5
Using unf_ext 0.0.7.1
Using email_reply_trimmer 0.1.3
Installing eventmachine 1.2.0.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/eventmachine-1.2.0.1/ext
/usr/local/bin/ruby -r ./siteconf20160522-8243-1yibai4.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160522-8243-1yibai4.rb extconf.rb 2>&1

Gem files will remain installed in /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/eventmachine-1.2.0.1 for inspection.
Results logged to /var/www/discourse/vendor/bundle/ruby/2.0.0/extensions/x86_64-linux/2.0.0-static/eventmachine-1.2.0.1/gem_make.out
Using excon 0.45.4
Using exifr 1.2.4
Using fabrication 2.9.8
Using fakeweb 1.3.0
Using multipart-post 2.0.0
Using fast_blank 1.0.0
Installing fast_stack 0.2.0 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/fast_stack-0.2.0/ext/fast_stack
/usr/local/bin/ruby -r ./siteconf20160522-8243-b66lhp.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160522-8243-b66lhp.rb extconf.rb 2>&1

Gem files will remain installed in /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/fast_stack-0.2.0 for inspection.
Results logged to /var/www/discourse/vendor/bundle/ruby/2.0.0/extensions/x86_64-linux/2.0.0-static/fast_stack-0.2.0/gem_make.out
Using fast_xs 0.8.0
Using ffi 1.9.10
Using flamegraph 0.9.5
Using fspath 2.1.1
Using sorcerer 1.0.2
Using guess_html_encoding 0.0.11
Using hashie 3.4.3
Using highline 1.7.8
Using hiredis 0.6.1
Using htmlentities 4.3.4
Using http_accept_language 2.0.5
Using image_size 1.4.1
Using in_threads 1.3.1
Using progress 3.1.1
Using jwt 1.5.2
Using kgio 2.10.0
Using libv8 3.16.14.13
Using listen 0.7.3
Using logster 1.2.3
Using lru_redux 1.1.0
Using metaclass 0.0.4
Using method_source 0.8.2
Using mock_redis 0.15.4
Using moneta 0.8.0
Using msgpack 0.7.4
Using multi_json 1.11.2
Using multi_xml 0.5.5
Using mustache 1.0.3
Using netrc 0.11.0
Using oauth 0.4.7
Using oj 2.14.3
Using ruby-openid 2.7.0
Using redis 3.3.0
Using pg 0.18.4
Using slop 3.6.0
Using puma 3.2.0
Using r2 0.2.6
Using bundler 1.12.0
Using rails_multisite 1.0.4
Using raindrops 0.15.0
Using rb-fsevent 0.9.7
Using trollop 2.1.2
Using ref 2.0.0
Using rinku 1.7.3
Using rmmseg-cpp 0.2.9
Using rspec-support 3.2.2
Using rtlit 0.0.5
Using sass 3.2.19
Using tilt 2.0.2
Using shoulda-context 1.2.1
Using simple-rss 1.3.1
Using simplecov-html 0.10.0
Using spork 1.0.0rc4
Using timecop 0.8.0
Using rake-compiler 0.9.9
Using tzinfo 1.2.2
Installing nokogiri 1.6.8.rc3 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.8.rc3/ext/nokogiri
/usr/local/bin/ruby -r ./siteconf20160522-8243-7ly6nb.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160522-8243-7ly6nb.rb extconf.rb 2>&1

Gem files will remain installed in /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.8.rc3 for inspection.
Results logged to /var/www/discourse/vendor/bundle/ruby/2.0.0/extensions/x86_64-linux/2.0.0-static/nokogiri-1.6.8.rc3/gem_make.out
Using rack-test 0.6.3
Using message_bus 2.0.0.beta.11
Installing rack-mini-profiler 0.10.1
Using rack-protection 1.5.3
Using mail 2.6.4
Using aws-sdk-core 2.2.9
Using babel-transpiler 0.7.0
Using uglifier 2.7.2
Using barber 0.11.1
Using ember-data-source 1.0.0.beta.16.1
Using sprockets 3.6.0
Using unf 0.1.4
An error occurred while installing eventmachine (1.2.0.1), and Bundler cannot
continue.
Make sure that `gem install eventmachine -v '1.2.0.1'` succeeds before bundling.

```

I tried “gem install bundler” as suggested by the logs, but that doesn’t work either.

---

<div class="post-metadata">

### Author: ![skx](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@skx](https://meta.discourse.org/u/skx)
#### Post date: [May 22, 2016, 4:15am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/8 "2016-05-22T04:15:33Z")

</div>

> [@prateekvarma](#):
>
> /usr/local/bin/ruby -r ./siteconf20160522-8243-1yibai4.rb extconf.rbCannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160522-8243-1yibai4.rb extconf.rb 2\>&1

It looks like this is your problem:

> “Cannot allocate memory”

The solution here is to stop apache, stop mysql, stop all the services you can, temporarily, such that you have free RAM and can build the gems. Then post-build you can restart them.

Failing that if you’re on a virtual machine pay for more RAM.

---

<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: [May 22, 2016, 4:21am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/9 "2016-05-22T04:21:40Z")

</div>

> [@skx](#):
>
> Failing that if you’re on a virtual machine pay for more RAM.

Or add a swap file or increase the size of your swap file.

---

<div class="post-metadata">

### Author: ![skx](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@skx](https://meta.discourse.org/u/skx)
#### Post date: [May 22, 2016, 4:23am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/10 "2016-05-22T04:23:54Z")

</div>

Good point. I guess take a look at this recent discussion:

- [https://meta.discourse.org/t/memory-useage-tips/44565/3](https://meta.discourse.org/t/memory-useage-tips/44565/3)

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 22, 2016, 4:28am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/11 "2016-05-22T04:28:32Z")

</div>

i use a 2 GB RAM server…and i have almost 1 GB free… pretty sure that is free enough.  
Any other ideas?

---

<div class="post-metadata">

### Author: ![skx](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@skx](https://meta.discourse.org/u/skx)
#### Post date: [May 22, 2016, 4:31am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/12 "2016-05-22T04:31:00Z")

</div>

If you read the link above, then visit the swap-file page you’ll see this:

> We recommend a 2GB swap file for Discourse, unless your server has 4GB or more of memory.

I think that means that you _should_ add the swap file and/or upgrade your RAM.

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 22, 2016, 4:32am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/13 "2016-05-22T04:32:23Z")

</div>

i see.. i’ll check that now. Thanks

---

<div class="post-metadata">

### Author: ![precessor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/precessor/32/120664_2.png) [@precessor](https://meta.discourse.org/u/precessor)
#### Post date: [May 22, 2016, 7:23am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/14 "2016-05-22T07:23:25Z")

</div>

I had this exact issue - Discourse on DO with 2GB RAM and no swap worked fine, except for updating from the Discourse dashboard. So I would always rebuild the app via SSH instead.  
Adding 1GB swap file fixed it for me; updating from the dashboard now works.

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 22, 2016, 8:24pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/15 "2016-05-22T20:24:46Z")

</div>

Hi,  
I have some basic questions about creating a swap file -

1.) since i run a 2GB ram server, what should be the size of the swap that i create, and why?  
2.) How will creating a swap file affect my server? If i create a 1 GB swap, will 1 GB be reserved just for the system processes for Discourse?  
3.) As the forum grows, will i need to increase the size of the swap? What will determine how much should it be increased? And will the method to increase the swap be the same?

Many thanks!

---

<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: [May 22, 2016, 11:12pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/16 "2016-05-22T23:12:40Z")

</div>

Just 2gb swap file is needed, it will mostly be used only during upgrades. If you have 4gb or more ram you may not need the swapfile.

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 22, 2016, 11:31pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/17 "2016-05-22T23:31:08Z")

</div>

sorry for the dumb queston, but will the swap file take 2 gb from the ram or from the storage drive?

---

<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: [May 22, 2016, 11:37pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/18 "2016-05-22T23:37:05Z")

</div>

From the disk only, that is the purpose of swap.

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 23, 2016, 12:07am UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/19 "2016-05-23T00:07:32Z")

</div>

Done. Created a 2 GB swap file and the upgrade works like a charm.

Here is the process - [Create a swapfile for your Linux server](https://meta.discourse.org/t/create-a-swapfile-for-your-linux-server/13880)

---

<div class="post-metadata">

### Author: ![prateekvarma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prateekvarma/32/57928_2.png) [@prateekvarma](https://meta.discourse.org/u/prateekvarma)
#### Post date: [May 24, 2016, 6:06pm UTC](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029/20 "2016-05-24T18:06:35Z")

</div>

Just want to add in - making the swap takes an additional around 300 MB of RAM. My total RAM usage for a starting forum is like 1700 MB now.

Discourse does take a toll on the RAM, but i guess it’s worth it.

[Next page](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029.md?page=2)
