{"id":647,"date":"2023-07-13T12:46:53","date_gmt":"2023-07-13T12:46:53","guid":{"rendered":"https:\/\/blog.hostinger.io\/support\/2023\/07\/13\/8124185-how-to-set-up-swap-on-hostinger-vps\/"},"modified":"2026-03-16T12:12:02","modified_gmt":"2026-03-16T12:12:02","slug":"8124185-how-to-set-up-swap-on-hostinger-vps","status":"publish","type":"post","link":"https:\/\/www.hostinger.com\/support\/8124185-how-to-set-up-swap-on-hostinger-vps\/","title":{"rendered":"How to Set Up SWAP on Hostinger VPS"},"content":{"rendered":"<p class=\"no-margin\"><b>SWAP space<\/b>, also known as <b>virtual memory<\/b>, is a crucial component of a <b>Linux<\/b> system that <b>helps manage memory usage efficiently<\/b>. <\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">On a <b><a href=\"https:\/\/www.hostinger.com\/vps-hosting\" target=\"_blank\" class=\"intercom-content-link\">Hostinger VPS<\/a><\/b>, setting up SWAP can provide <b>additional memory resources<\/b> and <b>improve the overall performance <\/b>of your server. In this article, we will guide you through the process of setting up SWAP on your <b>Hostinger VPS<\/b>.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_3ad038065e\">Prerequisites<\/h2><p class=\"no-margin\">Before proceeding with the steps below, please ensure that you have the following:<\/p><ul>\n<li>\n<p class=\"no-margin\">A <b><a href=\"https:\/\/www.hostinger.com\/vps-hosting\" target=\"_blank\" class=\"intercom-content-link\">Hostinger KVM VPS<\/a><\/b><\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">Basic knowledge of the <b><a href=\"https:\/\/www.hostinger.com\/tutorials\/linux-commands\" target=\"_blank\" class=\"intercom-content-link\">Linux command line<\/a><\/b><\/p>\n<\/li>\n<\/ul><p class=\"no-margin\">\n<\/p><h2 id=\"h_2fb60b4db4\">Step 1 &ndash; Check for Existing SWAP Space <\/h2><p class=\"no-margin\"><b><a href=\"\/support\/5723772-how-to-connect-to-your-vps-via-ssh\" target=\"_blank\" class=\"intercom-content-link\">Connect to your VPS via SSH<\/a><\/b> using your preferred terminal application and run the following command to check if there is an existing SWAP space:<\/p><p class=\"no-margin\">\n<\/p><pre><code>swapon --show<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">If the command returns output, you already have SWAP space set up. Skip to <b><a href=\"#h_0c9aa59d2d\" target=\"_blank\" class=\"intercom-content-link\">Step 4<\/a><\/b>.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_b2ba0ea308\">Step 2 &ndash; Create a SWAP File<\/h2><p class=\"no-margin\">Run the following command to <b>create a SWAP file<\/b> of the desired size (in this example, we&rsquo;ll use <b>2GB<\/b>):<\/p><p class=\"no-margin\">\n<\/p><pre><code>fallocate -l 2G \/swapfile<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Set the appropriate permissions on the file to restrict access:<\/p><p class=\"no-margin\">\n<\/p><pre><code>chmod 600 \/swapfile<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Format the file as SWAP:<\/p><p class=\"no-margin\">\n<\/p><pre><code>mkswap \/swapfile<\/code><\/pre><p class=\"no-margin\">\n<\/p><h2 id=\"h_d06b568bfc\">Step 3 &ndash; Enable the SWAP File<\/h2><p class=\"no-margin\"><b>Activate the SWAP file<\/b> by running the following command:<\/p><p class=\"no-margin\">\n<\/p><pre><code>swapon \/swapfile<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">To make the SWAP file persist across reboots, open the <b>\/etc\/fstab <\/b>file in a text editor:<\/p><p class=\"no-margin\">\n<\/p><pre><code>nano \/etc\/fstab<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Add the following line at the end of the file:<\/p><p class=\"no-margin\">\n<\/p><pre><code>\/swapfile none swap sw 0 0<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Save the changes and exit the text editor.<\/p><p class=\"no-margin\">\n<\/p><h2 id=\"h_0c9aa59d2d\">Step 4 &ndash; Adjust SWAP Settings (Optional)<\/h2><p class=\"no-margin\">By default, <b>Linux<\/b> <b>manages SWAP usage automatically<\/b>. However, you can adjust the behavior according to your requirements. <\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Open the <b>\/etc\/sysctl.conf <\/b>file:<\/p><p class=\"no-margin\">\n<\/p><pre><code>nano \/etc\/sysctl.conf<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">Add or modify the following line to <b>change the SWAP behavior<\/b>:<\/p><p class=\"no-margin\">\n<\/p><pre><code>vm.swappiness=10<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\"><b>NOTES<\/b><\/p><ul>\n<li>\n<p class=\"no-margin\">A value of <b>0<\/b> makes the kernel <b>avoid SWAP as much as possible<\/b><\/p>\n<\/li>\n<li>\n<p class=\"no-margin\">A value of<b> 100<\/b> makes the kernel <b>use SWAP aggressively<\/b><\/p>\n<\/li>\n<\/ul><p class=\"no-margin\">\n<\/p><h2 id=\"h_4331e82d5d\">Step 5 &ndash; Verify SWAP Setup<\/h2><p class=\"no-margin\">Run the command below to verify that the SWAP space is <b>active and being utilized<\/b>:<\/p><p class=\"no-margin\">\n<\/p><pre><code>swapon --show<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">It should display information about the SWAP file. You can also check SWAP usage using the free command:<\/p><p class=\"no-margin\">\n<\/p><pre><code>free -h<\/code><\/pre><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">The output will show information about the SWAP space and its usage.<\/p><p class=\"no-margin\">\n<\/p><p class=\"no-margin\">And that&rsquo;s it &ndash; you have successfully set up SWAP space on your <b>Hostinger VPS<\/b>! This additional memory resource can help improve the performance and stability of your server by efficiently managing memory usage &#127881; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Configuring and Optimizing SWAP memory for enhanced perform<\/p>\n","protected":false},"author":581,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"include_on_kodee":true,"footnotes":""},"categories":[199],"tags":[],"class_list":["post-647","post","type-post","status-publish","format-standard","hentry","category-vps-management"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/support\/8124185-how-to-set-up-swap-on-hostinger-vps\/","default":1}],"include_on_kodee":true,"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/647","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/comments?post=647"}],"version-history":[{"count":0,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/posts\/647\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/media?parent=647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/categories?post=647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/support\/wp-json\/wp\/v2\/tags?post=647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}