Install vcpkg on Ubuntu 20.04

The vcpkg is a cross-platform C/C++ package manager for downloading and building various libraries. The vcpkg is an open-source project developed by Microsoft which released under the MIT license.

This tutorial explains how to install vcpkg on Ubuntu 20.04.

Prepare environment

Make sure you have installed Git in your system. You can read post how to install it.

Also you need to install zip and unzip packages:

sudo apt update
sudo apt install -y zip unzip

For libraries compilation, you need to install build-essential and pkg-config packages:

sudo apt install -y build-essential pkg-config

Install vcpkg

Download vcpkg from GitHub repository:

wget -O vcpkg.tar.gz https://github.com/microsoft/vcpkg/archive/master.tar.gz

Create a new directory to store vcpkg and extract the tar.gz file to it:

sudo mkdir /opt/vcpkg
sudo tar xf vcpkg.tar.gz --strip-components=1 -C /opt/vcpkg

Run the following command to build vcpkg itself:

sudo /opt/vcpkg/bootstrap-vcpkg.sh

In /usr/local/bin directory we can create a symbolic link to the vcpkg command:

sudo ln -s /opt/vcpkg/vcpkg /usr/local/bin/vcpkg

Now vcpkg can be used as a system-wide command for all users. We can check vcpkg version with command:

vcpkg version

The tar.gz file is no longer needed, remove it:

rm -rf vcpkg.tar.gz

Testing vcpkg

We can use vcpkg install command to build and install libraries. For example, the following command installs zlib library:

sudo vcpkg install zlib:x64-linux

Run the following command to get a list of installed libraries:

sudo vcpkg list

Uninstall vcpkg

If you wish to completely remove vcpkg, delete the installation directory:

sudo rm -rf /opt/vcpkg

Remove symbolic link:

sudo rm -rf /usr/local/bin/vcpkg

You can also remove vcpkg cache and related directories:

sudo rm -rf /root/.cache/vcpkg
sudo rm -rf /root/.vcpkg
rm -rf ~/.vcpkg

For environment preparation we needed to install various packages. These packages and related dependencies can be completely removed with command:

sudo apt purge --autoremove -y zip unzip build-essential cpp make binutils pkg-config

This article has 1 comment

  1. Unknown Reply

    This is perhaps the most usefull tutorial on th e internet for a newbe cpp programmer. A simple explenation is sometimes the best explanation.

Leave a Comment

Your email address will not be published. Required fields are marked *