Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy

I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn

Very quickly adding swap to Ubuntu 14.04

#linux #technical

Following is the quickest way to add swap space to Ubuntu 14.04 installation. I am writing the post because I keep having to look this up and given the convenience and price of DigitalOcean’s base plan it is necessary for anything a bit heavier.

In fact, it is necessary for anything that would use nginx because the compilation normally fails when the machine does not have more then 1GB of memory.

sudo fallocate -l 8G /swapfile          # Create swap file.
                                        # Normally for smaller machines RAM x 2.

sudo chmod 600 /swapfile                # Change the permission of the swap file.

mkswap /swapfile                        # Needed for later versions

sudo swapon /swapfile                   # Turn the swap file on.

sudo nano /etc/fstab                    # Open fstab for editing to persist the changes.
/swapfile   none    swap    sw    0   0 # Paste this at the end of the file

Credit where credit is due.