VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04?comment=12767

โ‡ฑ How To Add Swap on Ubuntu 14.04 | DigitalOcean


Not using Ubuntu 14.04?
Choose a different version or distribution.
Ubuntu 14.04
๐Ÿ‘ How To Add Swap on Ubuntu 14.04

Introduction

One of the easiest way of increasing the responsiveness of your server and guarding against out of memory errors in your applications is to add some swap space. Swap is an area on a hard drive that has been designated as a place where the operating system can temporarily store data that it can no longer hold in RAM.

Basically, this gives you the ability to increase the amount of information that your server can keep in its working โ€œmemoryโ€, with some caveats. The space on the hard drive will be used mainly when space in RAM is no longer sufficient for data.

The information written to disk will be slower than information kept in RAM, but the operating system will prefer to keep running application data in memory and use swap for the older data. Overall, having swap space as a fall back for when your systemโ€™s RAM is depleted is a good safety net.

In this guide, weโ€™ll cover how to create and enable a swap file on an Ubuntu 14.04 server.

Note

Although swap is generally recommended for systems utilizing traditional spinning hard drives, using swap with SSDs can cause issues with hardware degradation over time. Due to this consideration, we do not recommend enabling swap on DigitalOcean or any other provider that utilizes SSD storage. Doing so can impact the reliability of the underlying hardware for you and your neighbors.

If you need to improve the performance of your server, we recommend upgrading your Droplet. This will lead to better results in general and will decrease the likelihood of contributing to hardware issues that can affect your service.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author

Former Senior Technical Writer at DigitalOcean, specializing in DevOps topics across multiple Linux distributions, including Ubuntu 18.04, 20.04, 22.04, as well as Debian 10 and 11.

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Youโ€™re missing a โ€˜pโ€™ in this line:

sudo sysctl vm.swapiness=10

should be:

sudo sysctl vm.swappiness=10

I also noticed your fstab has โ€˜defaultsโ€™ under options, it should be โ€˜swโ€™ instead. It is the default debian/ubuntu option for swap. โ€˜defaultsโ€™ is a great option for your userspace filesystem, but not ideal for swap.

/swapfile none swap sw 0 0

Hi Brandon:

Youโ€™re absolutely right on both points. Those were oversights on my part. Iโ€™ve updated the article to reflect your suggestions.

how much swap should we create for a 1gb ram droplet? (size of swap file)

@chris: A general rule of thumb that people use is to have twice your memory in swap. So if you have 1 GB of RAM, you want 2 GB of swap. Though that was from back in the day when people didnโ€™t have nearly as much memory as they usually do now. So 2 GB of swap is probably more than enough. If disk space is a concern, you can easily get away with 1 GB.

Nice article Justin. Is it absolutely necessary to have some swap (at least to begin with) when upgrading memory? If I have applications that mandate not to use swap. I set the swapiness to 0 on CentOS.

Youโ€™ve still got an error in the command:

sudo sysctl vm.swapiness=10

Should have another โ€˜pโ€™:

sudo sysctl vm.swappiness=10

Helpful article. Thanks.

Swap memory should appear on Virtualmin System information page as Virtual memory ?

๐Ÿ‘ Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOceanโ€™s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow โ€” whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

ยฉ 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.