> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Disable Swap in Linux
- URL: https://linuxhandbook.com/disable-swap-linux/
- Published: 2020-02-10T16:56:16.000Z
- Updated: 2024-09-09T14:12:55.000Z
- Description: In scenarios like changing the swap size, you should disable the swap first. This quick tutorial shows the steps for disabling swap in Linux.
- Author: Abhishek Prakash
- Tags: Tips

You may encounter a scenario where you need to disable the [swap in Linux](https://itsfoss.com/swap-size/?ref=linuxhandbook.com). Suppose you want to [change the swap size](https://linuxhandbook.com/increase-swap-ubuntu/). You should disable it before making any changes.

If for some reasons, you decided to disable swap in Linux, this tutorial shows you the steps to do it.

There are two kinds of swap space in Linux:

- swap partition (a dedicated partition)
- [swap file](https://itsfoss.com/create-swap-file-linux/?ref=linuxhandbook.com) (a file under root acting as swap)

A system can have either of the swap partition or swap file or both. You can [check active swap using command](https://linuxhandbook.com/check-swap-usage/):

```
swapon --show
```

However, more reliable information can be found in **/etc/fstab** file that shows all the swap on your system, active or inactive.

![Check Swap in fstab](https://linuxhandbook.com/content/images/2020/06/disable_swap_linux.png)

Now that you know how to locate your swap file or partition, let’s see how to disable it.

## Disable swap in Linux

If you want to disable a specific swap file or partition, provide its path like this:

```
sudo swapoff /dev/nvme0n1p2
```

An easier way is to disable all the active swap on your system like this:

```
sudo swapoff -a
```

If you check for active swap again using *swapon –show* command, you won’t see any swap anymore.

## Re-enable swap in Linux

If you want to reactivate a disabled swap space, you can use the swapon command like this:

```
sudo swapon /dev/nvme0n1p2
```

Or you can enable all the available swap space using this command:

```
sudo swapon -a
```

## Deleting swap space

If you want to delete the swap partition or file, you’ll have to **first disable it**. You just saw the steps for disabling it.

Now, if you have a swap file, deleting it is the same as [removing any file in Linux](https://linuxhandbook.com/remove-files-directories/).

```
sudo rm path_to_swap_file
```

If you have a swap partition, you can delete the partition using [fdisk](https://en.wikipedia.org/wiki/Fdisk?ref=linuxhandbook.com) command.

The important part is that you should also remove the entry for the deleted swap file or partition from the /etc/fstab file.

I hope you found this quick little tutorial helpful in handling swap space to your Linux system. On a related topic, you may read about [clearing the swap on your Linux system](https://linuxhandbook.com/clear-swap/).