Creating a Swap File in Linux

To Swap or Not to Swap

A swap file is a location on your disk that the Linux kernel can use to provide extra memory when your system is running low. Most Linux distribution installers will create a partition for this purpose, but this is a waste of space on most modern systems, especially when using SSD drives with limited space.

That doesn’t mean you should disable swap entirely, though. Not having a swap file means that programs may occasionally be terminated for lack of free memory even in moderately loaded systems. Rather than dedicating an entire partition to this purpose, a swap file is perfectly suitable and easy to configure without having to repartition your drive.

You May Already Be Swapping

Before creating a swap file, you should check to see if there is any active swap file or partition. To do this, run a Terminal or SSH in to your machine and run:


If nothing is returned, then there is no swap file. If so, the details of the file or partition will be shown.

Creating the Swap File

If you have plenty of memory, I’d recommend creating a 2 GB swap file. It’s what I usually setup on virtual servers. To do this, run:

sudo dd if=/dev/zero of=/swap bs=64M count=32
sudo chmod 0600 /swap
sudo mkswap /swap

Note in this case I’m telling the “dd” command to write 64 MB of zeros 32 times, which totals 2097120 bytes, or 2 GB. If you wanted to use a 1 GB file, you would specify 16 for the count instead of 32.

The next step is to add this swap file to the /etc/fstab file. This will tell Linux to activate the file upon boot. To do so, run:

sudo echo "/swap swap swap defaults 0 0" >> /etc/fstab

Note: If you aren’t copying and pasting the line above, it is imperative that you double check your typing. If you don’t use >> near the end, it could clobber your /etc/fstab file and create massive problems. The >> tells echo to add it to the end, whereas > would tell it to overwrite the file. Be careful!

To activate the swap file, run:

swapon -a

If you run the swapon command again by itself without any parameters, you’ll note the new swap file is now active.

What is the Best Linux Distribution for Web Developers?

Best Linux Distribution for Web Development

I’ve been asked this question more than once, and given how little information there is on the Internet about this important topic, I felt it needed covering with an in-depth rumination of the available options.

If you are an experienced Linux user, then the obvious answer would be to use the distribution you prefer. But few seasoned Linux desktop users have just one favorite distribution. If it were that simple, there wouldn’t be thousands of distributions. Don’t worry, I won’t stop at that trite answer – we’re going to dive deep into your options.

Before we get started, though, I should mention that this article will be primarily focused on web developers and not web or graphic designers. The needs of graphical designers are completely different than developers, and while web design has a bit more overlap, it still often requires access to Photoshop, something that is still a pain on Linux.

Integrating with your web hosting account would commonly be done with Git, Subversion, rsync, or SFTP. Nearly every Linux distribution makes using these tools easily, and in many cases you’ll find them pre-installed.

For a web developer, a common tool stack would include:

  • Chrome and Firefox
  • A decent terminal
  • SSH, SFTP, rsync, Git, and possibly Subversion
  • A developer’s text editor (Vim, Emacs, Atom, etc.)
  • GIMP (for simple resizing, touch-ups, conversions, etc.)
  • Node.js with npm, Ruby, and Python
  • Simple Apache and PHP configuration

There are other tools that I use on a Linux web development machine, but these are the most important ones. Any distribution we discuss below must meet these requirements.

Debian / Debian Testing

A go-to option for many users is Debian. It has a ridiculously large pool of software to install, is extremely stable, and has a large community and excellent documentation.

The downside to Debian for web development (or for most uses, for that matter) is that the default stable install is generally 2-3 years old. For casual use this isn’t often a problem, but web development often requires more recent versions so this presents an issue.

Using Debian Testing can help with this at the cost of some stability. Switching from Debian to Debian Testing is very easy and generally is problem free, though since you will be at the (mostly) bleeding edge, you could experience some version dependency issues. If you find yourself using Debian testing but have trouble managing the software stack, you may want to consider an Ubuntu derivative which is based on a periodic snapshot of Debian testing.

Ubuntu Derivatives

Ubuntu is an excellent choice for web development, but its current user interface, Unity, is not acceptable to many, so using an Ubuntu derivative is generally a better option. This will change in the next version of Ubuntu, but for now, the vanilla distribution is not going to suit most people’s desktop workflow.

In the Ubuntu category, I would recommend Ubuntu Studio. It uses the XFCE desktop, comes pre-installed with many of the tools you’ll need, and the low-latency kernel feels a bit snappier even outside of audio applications.

With any Ubuntu derivative, I recommend the latest release and not the LTS (long-term support) version, because the LTS release can lag behind as much as Debian stable and quickly become out of date.

RedHat Derivatives (Fedora, CentOS)

I like CentOS for our servers, but I don’t have as much experience with RedHat on the desktop because I have generally been part of the Debian community. That said, the last time I installed Fedora on a machine about 6 months ago I was impressed.

Before we go further down the red path, I would strongly advise not using CentOS as a desktop for web development. It suffers the same dated issue that plagues Debian or Ubuntu LTS. Stability is fantastic for a server, but serious desktop use demands up to date software. For that reason, we will only discuss Fedora in this section.

Fedora has, in my opinion, the best integration of the GNOME desktop. While that isn’t my favorite interface, they tie it into the system better than any other distribution. Their optimizations bring life to what is usually an uneven experience. Of course, if GNOME isn’t your thing, you can always use KDE, Cinnamon, or others with Fedora Spins.


Arch Linux is an excellent choice for your open-source web development desktop. I find their Ruby and Python version management scheme superior, but the distribution comes with some major caveats that you should consider before going down the Arch road:

  • Arch Linux demands a high level of Linux experience and competency. If your use of the command line is limited, Arch isn’t for you.
  • You will nearly always be on the bleeding edge with Arch. While this isn’t generally an issue with web development, things can and do break (just like with Debian testing), so you should be prepared for this.

If you are stuck with a problem in Arch Linux, it does provide outstanding documentation. Their wiki can help you solve nearly any problem you might encounter.


Gentoo was one of my favorite distributions in the 2000 to 2010 era, and I used it as my primary desktop for several years. It’s a fantastic source-only distribution that provides an amazing amount of flexibility and customization. Because everything is compiled from source, you can get performance and patches that are difficult if not impossible to obtain from other distributions.

However, you will face the following issues with Gentoo:

  • Like Arch Linux, Gentoo requires a fair depth of Linux knowledge and comfort with the command line.
  • Since most pieces of software are compiled, you’ll spend a lot of time waiting for your computer to finish with installation. On older machines this could take several days, but modern processors finish this task in much less time. Still, if time is an issue for you, Gentoo probably won’t be your first choice.
  • You’ll always be on the bleeding edge, so problems may occur more often than they do with a more stable distribution.
  • An update to a particular library may necessitate the recompile of many major components of your system. Again, on modern CPUs this isn’t a considerable issue, but it is something to weigh, especially if you’re using older hardware.

This is confusing! What about Windows?

Using Microsoft Windows 10 as a web development platform is certainly an option. In fact, if you’re working on C#/ASP.NET websites, its your best choice. But when working with PHP, Ruby, Python, or Node.js, Windows does present some challenges (mainly lack of a decent terminal – and no, PowerShell isn’t quite there yet for open source web development).

If you are going to use Windows, installing one of these distributions in a Virtual Machine (VirtualBox is both free and especially helpful for this) will make your life a lot easier. Many of these open source web development tools were just not originally designed to run on Windows, and while Microsoft and others have made great strides on this front, you’ll save yourself a lot of headache by using a virtual machine.

Incidentally, hosing PHP on Windows Server is not only an option but increasingly a stable and mostly performant choice. Linux is still faster in this regard, but Microsoft is catching up in terms of performance and security to the traditional LAMP stack.


macOS has a big advantage in open source web development – it’s based on UNIX (BSD). Many tools run well in its terminal, and with access to Adobe programs without a virtual machine, it’s hard to deny the feasibility and attractiveness of a macOS web development system.

That said, macOS does present a walled garden of hardware that can be very frustrating to some, and the cost factor is an issue. Since this article is primarily about Linux, we won’t delve too much into this option.


There is no single recommendation I can possibly make for your web development Linux distribution. While I personally find Ubuntu Studio to be the most well-rounded option (with Fedora coming in at second place), each distribution has pluses and minuses to consider.

If you only have one computer, I recommend installing each of these in a virtual machine to test it out and see how it will work for your purposes. Do more than just install – actually perform real web development work on the system to put it through its paces. Soon you’ll be able to tell if that option is right for you.

Once you’ve found your preference, dual booting is probably a better choice for most people due to the performance of most Linux desktop systems under virtual machine hypervisors. If you have more than one computer, especially a spare desktop, installing your choice of Linux on it for testing purposes is highly recommended. As long as you use a good data retention and backup scheme (i.e. portable or NAS drives that are backed up, etc.), reinstalling to try another selection is a breeze.

I hope this guide has been helpful to you. If you have any questions, please let me know in the comments below. I’d also like to hear what you use for your web development system.