How To Install cargo on Ubuntu 20.04

In this tutorial we learn how to install cargo on Ubuntu 20.04. cargo is Rust package manager Rust package manager

Introduction

In this tutorial we learn how to install cargo on Ubuntu 20.04.

What is cargo

cargo is:

Cargo is a tool that allows Rust projects to declare their various dependencies, and ensure that you’ll always get a repeatable build.

To accomplish this goal, Cargo does four things:

  • Introduces two metadata files with various bits of project information.
  • Fetches and builds your project’s dependencies.
  • Invokes rustc or another build tool with the correct parameters to build your project.
  • Introduces conventions, making working with Rust projects easier.

Cargo downloads your Rust project’s dependencies and compiles your project.

Package: cargo Architecture: amd64 Version: 0.42.0-0ubuntu1 Multi-Arch: allowed Priority: extra Section: universe/devel Origin: Ubuntu Maintainer: Ubuntu Developers [email protected] Original-Maintainer: Rust Maintainers [email protected] Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 10261 Depends: libc6 (>= 2.29), libcurl3-gnutls (>= 7.28.0), libgcc-s1 (>= 4.2), libgit2-28 (>= 0.28.1), libssh2-1 (>= 1.2.5), libssl1.1 (>= 1.1.0), zlib1g (>= 1:1.1.4), rustc (>= 1.24), binutils, gcc | clang | c-compiler Suggests: cargo-doc, python3 Filename: pool/universe/c/cargo/cargo_0.42.0-0ubuntu1_amd64.deb Size: 2808896 MD5sum: 1191370aba4412d7bc0c7f67c987b9e9 SHA1: 30d919012e3b438d84fa2e381306865952507d1d SHA256: 817d9b999209c56b1ed2fe75dc5a3f07840a6bc00a16c7748917279dbbf6d56b Homepage: https://crates.io/ Description-en: Rust package manager Cargo is a tool that allows Rust projects to declare their various dependencies, and ensure that you’ll always get a repeatable build.

To accomplish this goal, Cargo does four things:

  • Introduces two metadata files with various bits of project information.
  • Fetches and builds your project’s dependencies.
  • Invokes rustc or another build tool with the correct parameters to build your project.
  • Introduces conventions, making working with Rust projects easier.

Cargo downloads your Rust project’s dependencies and compiles your project.

There are three methods to install cargo 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 cargo Using apt-get

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

sudo apt-get update

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

sudo apt-get -y install cargo

Install cargo Using apt

Update apt database with apt using the following command.

sudo apt update

After updating apt database, We can install cargo using apt by running the following command:

sudo apt -y install cargo

Install cargo 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 cargo using aptitude by running the following command:

sudo aptitude -y install cargo

How To Uninstall cargo on Ubuntu 20.04

To uninstall only the cargo package we can use the following command:

sudo apt-get remove cargo

Uninstall cargo And Its Dependencies

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

sudo apt-get -y autoremove cargo

Remove cargo Configurations and Data

To remove cargo configuration and data from Ubuntu 20.04 we can use the following command:

sudo apt-get -y purge cargo

Remove cargo configuration, data, and all of its dependencies

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

sudo apt-get -y autoremove --purge cargo

References

Summary

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