Conda is an open-source package management system and environment management system for installing multiple versions of software packages and their dependencies. It is mainly developed for Python and not tied to any specific programming language. Conda allows you to install many programming languages in multiple different environments.

In this post, we will show you how to create Rust virtual environments using Conda in Linux.

Prerequisites

  • A server running Ubuntu 20.04.
  • A root password is configured on the server.

Install Required Dependencies

First, update your system packages to the latest version with the following command:

apt-get update -y

Once all the packages are updated, install other required packages with the following command:

apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6 -y

Once all the packages are installed, you can proceed to the next step.

Install Anaconda

First, download the Anaconda installation script with the following command:

wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh

Once the script is downloaded, run the downloaded script with the following command:

bash Anaconda3-2021.05-Linux-x86_64.sh

You will be asked to type yes or no as shown below:

Please answer ‘yes’ or ‘no’:’

>>> yes

Anaconda3 will now be installed into this location:
/root/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]

Once the Anaconda has been installed, activate the Conda environment with the following command:

source ~/.bashrc

Create Rust Virtual Environments Using Conda

The Rust toolchain installer provides a rustup utility to install Rust on Linux. However, you can also use the Conda package manager to install and manage the Rust programming language.

To create a new Rust environment, run the following command:

conda create -c conda-forge -n rustenv rust

Once the process has been finished, you should get the following output:

#
# To activate this environment, use
#
#     $ conda activate rustenv
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Next, verify the Rust environment with the following command:

conda info --envs

You should see the following output:

# conda environments:
#
base                  *  /root/anaconda3
rustenv                  /root/anaconda3/envs/rustenv

Next, you will need to activate the Rust environment. You can activate it using the following command:

conda activate rustenv

You should get the following output:

(rustenv) [email protected]:~# 

Now, verify the Rust version with the following command:

rustc --version

You should see the following output:

rustc 1.53.0 (53cb7b09b 2021-06-17)

You can also check the Corgo package version with the following command:

cargo --version

You should see the following output:

cargo 1.53.0 (4369396ce 2021-04-27)

Add Cargo Environment to your SYstem Path:

Next, you will need to add a Cargo environment to your system path to make it permanent.

To do so, edit the .bashrc file with the following command:

nano ~/.bashrc

Add the following lines:Advertisement

export PATH=/root/.cargo/bin:$PATH

Save and close the file then activate the environment with the following command:

source ~/.bashrc

Deactivate and Delete Rust Environment

To deactivate the Rust environment, run the following command:

conda deactivate

Next, delete the Rust environment permanently from your system using the following command:

conda env remove -n rustenv

Conclusion

Congratulations! you have successfully created a Rust environment using Conda. You can now start creating your first project using Rust.

<img alt="Hitesh Jethva" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/07/echo/hitesh-80.jpg60f6f0f91e5d7.jpg" ezimgfmt="rs rscb4 src ng ngcb4" src="data:image/svg xml,”>

About Hitesh Jethva

Over 8 years of experience as a Linux system administrator. My skills include a depth knowledge of Redhat/Centos, Ubuntu Nginx and Apache, Mysql, Subversion, Linux, Ubuntu, web hosting, web server, Squid proxy, NFS, FTP, DNS, Samba, LDAP, OpenVPN, Haproxy, Amazon web services, WHMCS, OpenStack Cloud, Postfix Mail Server, Security etc.