This creates a 1gb swap partition (1024mb) … replace this number in the command below with whatever size you’d like the partition to be. Generally a good approach is to make it the same size as your physical (or virtual) memory.
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024 /sbin/mkswap /var/swap.1 /sbin/swapon /var/swap.1
Also add the following so the swap partition is enabled on boot
sudo nano /etc/fstab /var/swap.1 swap swap defaults 0 0