I am going to install ubuntu 18.4 (dual booting with windows). I currently have 4GB RAM. I am going to add 8GB RAM in the next month or so. so, while I am installing ubuntu how much swap area should I use? Should I use it according to 4GB RAM or 8GB RAM? . Doubt 2: would it matter how much space I use for the swap? When I searched how much space I should use I saw many methods for choosing. can I add space as I like? Is there a specific rule? I don't know what to do, please help me.

  • 2
    If you use a swap partition, selecting the size is important. However Ubuntu 18.04 defaults to a swap file by default, meaning it can be changed easily, and the choice/size is far less important. I'd opt for swap file (esp. if you're using encryption), unless you have a reason for swap partition (ie. dual booting with another GNU/Linux where you'll share the space & not hibernate etc).
    – guiverc
    Apr 19, 2020 at 13:23
  • I'd say let the installation process decide on the appropriate size of swap file based on your current hardware. Choose the default side by side installation option for Ubuntu. When you add more RAM, you may change the file size, or leave it as is unless you are running out of disk space.
    – user68186
    Apr 19, 2020 at 13:51
  • @Raffa The OP's question was "how much swap area should I use?". How does your link answer that question?
    – heynnema
    Apr 19, 2020 at 18:18

1 Answer 1



With your decision to move from 4G RAM to 12G RAM, comes a very important decision. Memory is best installed in pairs of exactly similar RAM sticks. This is so the system can take the speed advantage of memory interleaving. You should consider either, adding another 4G RAM stick, or replacing the current 4G stick with two 8G sticks.


Good question. Swap and swap sizing is important. You'll probably get a ton of opinions about it.

Assuming that you don't already have a /swapfile or swap partition, go ahead and create a 4G /swapfile. To check for an existing /swapfile or swap partition, use these commands:

free -h

ls -al /swapfile

grep -i swap /etc/fstab

To create a 4G /swapfile...

Note: Incorrect use of the dd command can cause data loss. Suggest copy/paste.

Note: The first two commands may show an error if no current /swapfile exists.

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm 4G RAM and 4G swap

Add this line to /etc/fstab...

Note: This assumes no existing swap line in /etc/fstab.

/swapfile    none    swap    sw      0   0

Reboot and confirm proper operation.

  • I haven't installed ubuntu. I am going to install now. so when I install it should I choose specific swap space like twice of ram or so. Or can I choose a random number?
    – aqwertya
    Apr 19, 2020 at 15:15
  • @aqwertya I don't believe that the Ubuntu installer will allow you to specify swap size at installation time, and probably defaults to 2G, which is too small for 4G RAM. I'd recommend the 4G swap that I specify in my answer. This will also work if/when you decide on more RAM.
    – heynnema
    Apr 19, 2020 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .