You can create a swap file (as detailed in the mkswap manual page), but beware that swap files come with caveats – in particular hibernate will not work without some serious messing around.
It is generally considered much better to have one or more dedicated swap partitions. You can create them with the fdisk implementation of your choice, or GParted if you prefer a graphical method. This does require free (unpartitioned) space on the disk though. If you have multiple disks, creating a swap partition on each is a good idea, as the kernel can spread the load between them which is potentially faster.
If you want hibernate to work (which is really the main purpose of swap in these days of massive RAM), you need at least as much swap as RAM – the traditional recommendation is 2 x RAM.
Once you've created the swap partition, you need to add it to /etc/fstab. Do the following for each swap partition:
1) Create a partition to use. For a partition, use GParted unless you're comfortable with something more technical, or using LVM. GParted will format the partition for you, but other tools generally won't so you need to do that on the command line. Open a terminal and run:
Code:
sudo mkswap /dev/sdxn
where /dev/sd
xn is your newly created swap partition.
2) Enable the swap partition now (so you don't need to reboot to use it):
Code:
sudo swapon /dev/sdxn
3) Get the partition's UUID:
This should output a line including 'UUID="blahblahblah"'
4) Add the swap partition to the end of /etc/fstab so future boots remember it:
Code:
UUID=blahblahblah swap swap defaults 0 0