This page looks best with JavaScript enabled

Create Swap file on Cloud VM (AWS, GCloud, or Azure)

 ·  ☕ 1 min read  ·  ✍️ Chris Titus

Use the commands below to create swap file on a micro instance with a Linux operating system. This creates a 2GB Swap file to help alleviate low system ram. Consequently, this is great for those using micro instances in the cloud that have under 1 GB of memory.


Run the following from your SSH window

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s`

then change fstab (/etc/fstab) so it automatically mounts your swap file on startup

/swapfile none swap sw 0 0

Afterward, check if your swap file is operating properly withtop or htop.

I live stream on Twitch and encourage you to drop in and ask a question. I regularly publish on YouTube and, but if you need immediate assistance, check out the Terminal Cafe with Discord Invite Link.

Share on

Chris Titus
Chris Titus
Tech Content Creator