How to compile and install Varnish-cache on Linux

I used Ubuntu 12.04 LTS on Amazon EC2 to download, compile, and install Varnish Cache that claims to (typically) speed up delivery by a factor of 300x to 1000x .

As of this writing, you can find the latest stable release at https://www.varnish-cache.org/releases and under the 'Source' column you have the compressed source code file ready to be downloaded. I downloaded and installed version 4.0.3.

Prerequisites:

I had to install a few libraries on my system before I could compile and install Varnish. Please note that you may need to install more or less dependencies depending upon your current configuration. See https://www.varnish-cache.org/docs/4.0/installation/install.html#build-dependencies-on-debian-ubuntu for a list of dependencies on common platforms.

For example, on my particular system, I had to install the following two libraries before I could successfully compile and install Varnish cache.

sudo apt-get install libedit-dev
sudo apt-get install libpcre3-dev

Download, compile, and install Varnish Cache on Linux:

Then, I did the following to download, compile, and install it at /opt/varnish-4.0.3. Please make sure you verify the integrity of the downloaded file (based on your security requirement like checking checksum for example).

wget https://repo.varnish-cache.org/source/varnish-4.0.3.tar.gz
tar xzf varnish-4.0.3.tar.gz
cd varnish-4.0.3
./autogen.sh
./configure --prefix=/opt/varnish-4.0.3
make 
make check
sudo make install # or 'make install' (if you are root)

Please note that if you use the --prefix option then files will be installed at the location specified and you'll manually have to adjust PATHs and startup scripts etc. However, I like this approach because it allows me to use multiple versions on the same system and I know where files are located.

Test your Varnish Cache installation:

Assuming that all of the above completed successfully, you should have Varnish installed under /opt/varnish-4.0.3. You can double check by running the command below:

/opt/varnish-4.0.3/sbin/varnishd -V

Also, on my systems, I normally use symlinks to always use the latest stable releases (after thorough testing, of course). Here is how you can do that:

cd /opt
sudo ln -s /opt/varnish-4.0.3 ./varnish

Test again by running the following command:

/opt/varnish/sbin/varnishd -V

Final setup on Linux:

You can also add Varnish's binary folder to your shell's PATH environment variable, so as to be able to run Varnish (and other tools) from anywhere (without using the absolute path, that is /opt/ part).

See Working with BASH environment variables for some details on how to work with BASH environment variables.


Did this tutorial help a little? How about buy me a cup of coffee?

Buy me a coffee at ko-fi.com

Please feel free to use the comments form below if you have any questions or need more explanation on anything. I do not guarantee a response.

IMPORTANT: You must thoroughy test any instructions on a production-like test environment first before trying anything on production systems. And, make sure it is tested for security, privacy, and safety. See our terms here.