How To Install cloudsql-proxy on Ubuntu 20.04

In this tutorial we learn how to install cloudsql-proxy on Ubuntu 20.04. cloudsql-proxy is connect securely to a 2nd generation Cloud SQL DB

Introduction

In this tutorial we learn how to install cloudsql-proxy on Ubuntu 20.04.

What is cloudsql-proxy

cloudsql-proxy is:

The Cloud SQL Proxy allows a user with the appropriate permissions to connect to a Second Generation Google Cloud SQL database without having to deal with IP whitelisting or SSL certificates manually. It works by opening unix/tcp sockets on the local machine and proxying connections to the associated Cloud SQL instances when the sockets are used.

Optional functionality can be enabled (–fuse) with access to /dev/fuse as well as the fusermount binary.

By default, the proxy will authenticate under the default service account of the Compute Engine VM it is running on. Therefore, the VM must have at least the sqlservice.admin API scope (“https://www.googleapis.com/auth/sqlservice.admin") and the associated project must have the SQL Admin API enabled. The default service account must also have at least WRITER/EDITOR privileges to any projects of target SQL instances.

There are three methods to install cloudsql-proxy on Ubuntu 20.04. We can use apt-get, apt and aptitude. In the following sections we will describe each method. You can choose one of them.

Install cloudsql-proxy Using apt-get

Update apt database with apt-get using the following command.

sudo apt-get update

After updating apt database, We can install cloudsql-proxy using apt-get by running the following command:

sudo apt-get -y install cloudsql-proxy

Install cloudsql-proxy Using apt

Update apt database with apt using the following command.

sudo apt update

After updating apt database, We can install cloudsql-proxy using apt by running the following command:

sudo apt -y install cloudsql-proxy

Install cloudsql-proxy Using aptitude

If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude using the following command.

sudo aptitude update

After updating apt database, We can install cloudsql-proxy using aptitude by running the following command:

sudo aptitude -y install cloudsql-proxy

How To Uninstall cloudsql-proxy on Ubuntu 20.04

To uninstall only the cloudsql-proxy package we can use the following command:

sudo apt-get remove cloudsql-proxy

Uninstall cloudsql-proxy And Its Dependencies

To uninstall cloudsql-proxy and its dependencies that are no longer needed by Ubuntu 20.04, we can use the command below:

sudo apt-get -y autoremove cloudsql-proxy

Remove cloudsql-proxy Configurations and Data

To remove cloudsql-proxy configuration and data from Ubuntu 20.04 we can use the following command:

sudo apt-get -y purge cloudsql-proxy

Remove cloudsql-proxy configuration, data, and all of its dependencies

We can use the following command to remove cloudsql-proxy configurations, data and all of its dependencies, we can use the following command:

sudo apt-get -y autoremove --purge cloudsql-proxy

References

Summary

In this tutorial we learn how to install cloudsql-proxy package on Ubuntu 20.04 using different package management tools: apt, apt-get and aptitude.