Installing Varnish Cache on Linux: guide and advantages

Instalar Varnish Cache para acelerar la carga web

Accelerating a website load speed by installing Varnish Cache on Linux is a simple way to improve SEO and increase visibility. In this post we are going to explain how to install Varnish Cache step by step on different Linux distributions.

Reasons to install Varnish Cache for web acceleration

Loading a web page as fast as possible is essential. The impact of a website load speed on its position on search engines like Google or Bing is significant. Since it is closely related to the user experience.

For instance, Google’s “Core Web Vitals” are a good reference for optimizing the loading speed of web pages on desktop and mobile devices. These metrics are closely related to a web page’s response time and interaction time, thus it is important that web pages load content as fast as possible.

A solution to accelerate a website load speed is using Varnish.

Varnish Cache is a memory cache to serve static content — such as images, JavaScript files, CSS sheets or pages that do not often change — directly from the server’s RAM memory. This allows loading pages faster, because it is not necessary to search in the hard disk (which is considerably slower) where the content is stored, load it and serve it.

And that’s not all! By using Varnish, the server’s processor/CPU usage will also be lower.

Moreover, using a CDN solution is also a simple and efficient way of accelerating your web load speed. Besides, a CDN allows adding WAF security options and other additional advantages, in addition to the Varnish layer.

But let’s get to the point! How can you install Varnish Cache?

How to install Varnish Cache on Linux distributions

In this post we are going to explain step by step how to install Varnish on several widely used Linux distributions: Ubuntu, Rocky Linux, CentOS and Red Hat Enterprise Linux (RHEL).

Although versions 6.6 and 7.0 of Varnish are already available, this guide will focus on the installation of Varnish Cache 6.0 LTS, as its authors recommend. Moreover, the LTS version offers a longer maintenance period, which provides greater stability and extended support.

Installing Varnish Cache on Ubuntu Linux

Ubuntu is a popular choice among servers; especially its LTS version. Therefore, in this guide we have opted for using Ubuntu 20.04 LTS for installing Varnish.

If you prefer not to install the LTS version of Varnish, Ubuntu 20.04 LTS includes the version 6.2 in its repository. In this case, it would only be necessary to use the following command to install it:

apt install -y varnish

However, in order to use Varnish Cache 6.0 LTS in Ubuntu 20.04 LTS — so that you can benefit from extended support both for caching and the operating system, here are the steps you need to follow.

Firstly, you need to import the GPG key from the APT repository of Varnish 6.0 LTS:

sudo curl -s -L https://packagecloud.io/varnishcache/varnish60lts/gpgkey | sudo apt-key add -

Once it is imported, you need to create a file for the repository:

sudo tee /etc/apt/sources.list.d/varnish60lts.list > /dev/null <<EOF
deb https://packagecloud.io/varnishcache/varnish60lts/ubuntu/ focal main
EOF

Then, you need to force APT to use the version from packagecloud.io. — since the main repository does only include the version 6.2:

sudo tee /etc/apt/preferences.d/varnishcache > /dev/null <<-EOF
Package: varnish varnish-*
Pin: release o=packagecloud.io/varnishcache/*
Pin-Priority: 1000
EOF

The next step is to instruct the system to read the repository packets that have just been added:

apt update

Finally, after completing all the previous steps, you just need to install Varnish Cache using the following command:

apt install varnish

Installing Varnish Cache on Rocky Linux

This enterprise-grade distribution, inherited from CentOS, includes by default the version 6.0 of Varnish. Thus, the installation is really simple, since you only need to use the following command:

dnf -y update
dnf install @varnish

Installing Varnish Cache on CentOS 7 and RHEL 7

Although the version 7 of CentOS and RHEL are not very common anymore, they are still widely installed.

To install Varnish Cache on CentOS 7 and RHEL 7, it is necessary to enable the EPEL (Extra Packages for Enterprise Linux) repository, add an additional repository for Varnish 6.0 LTS (since EPEL includes the version 4.0, which is too old) and finally install it.

So, start by installing the EPEL repository:

yum install -y epel-release

After doing so, install the repository of Varnish 6.0 LTS from packagecloud.io:

curl -L -s https://packagecloud.io/install/repositories/varnishcache/varnish60lts/script.rpm.sh | sudo bash

Finally, after completing all the previous steps, you only need to install Varnish Cache 6.0 LTS using the following command:

yum install -y varnish

Following these simple steps, you can easily increase the load speed of any website using Varnish. Nevertheless, of course, there are additional factors that can slow down a web page load speed, as we explain in our post about the aspects that can slow down a website.

Moreover, depending on the size and complexity of the project, relying on a specialized team of system administrators can be the best choice.

Share it on Social Media!

Cookies customization
Stackscale, Grupo Aire logo

By allowing cookies, you voluntarily agree to the processing of your data. This also includes, for a limited period of time, your consent in accordance with the Article 49 (1) (a) GDPR in regard to the processing of data outside the EEA, for instead, in the USA. In these countries, despite the careful selection and obligation of service providers, the European high level of data protection cannot be guaranteed.

In case of the data being transferred to the USA, there is, for instance, the risk of USA authorities processing that data for control and supervision purposes without having effective legal resources available or without being able to enforce all the rights of the interested party. You can revoke your consent at any moment.

Necessary Cookies

Necessary cookies help make a web page usable by activating basic functions such as the page navigation and the access to secure areas in the web page. The web page will not be able to work properly without these cookies. We inform you about the possibility to set up your browser in order to block or alert about these cookies, however, it is possible that certain areas of the web page do not work. These cookies do not store any personal data.

- moove_gdpr_popup

 

Analytical cookies

Analytical cookies allow its Editor to track and analyze the websites’ users behavior. The information collected through this type of cookie is used for measuring the activity on websites, applications or platforms, as well as for building user navigation profiles for said websites, application or platform, in order to implement improvements based on the analysis of data on the usage of the service by users.

Google Analytics: It registers a single identification used to generate statistical data about how the visitor uses the website. The data generated by the cookie about the usage of this website is generally transferred to a Google server in the USA and stored there by Google LLC, 1600 Amphitheatre Parkway Mountain View, CA 94043, USA.

- _dc_gtm_UA-XXXXXXXX-X

- _gat_gtag_UA_XXXXXXXX_X

- _ga

- _gcl_au

- _gid