This article is from the Frequently Asked Questions for Linux, the Free/Open Source UNIX-like operating system kernel that runs on many modern computer systems. Maintained by David C. Merrill with numerous contributions by others. (v1.0).
A: In addition to a swap partition, Linux can also use a swap file. Some programs, like g++, can use huge amounts of virtual memory, requiring the temporary creation of extra space. To install an extra 64 MB of swap space, for example, use the following shell commands:
# dd if=/dev/zero of=/swap bs=1024 count=65535 # mkswap /swap # swapon /swap
The count= argument to dd determines how big the swap file will be. In this example the swap file's name is /swap, but the name and location are, generally, arbitrary, depending only on the file system's available space and your having write permissions in the directory.
When you don't need the swap space any more, remove it with the following statements:
# swapoff /swap # rm /swap
Take a look also at the Installation HOWTO and Installation & Getting Started for detailed instructions.
If that still doesn't provide enough swap space, refer to How To Have More Than 128Mb of Swap.