# How to install Rust on your machine in DETER
## 1. Install tarball file
Install tarball file that contains pre-compiled binaries, which are targeted for our host machine (x86_64-unknown-linux-gnu for machines in DETER). We are installing this file to perform an offline installation from our machine in DETER. You can download the file from [https://forge.rust-lang.org/infra/other-installation-methods.html#standalone-installers](https://forge.rust-lang.org/infra/other-installation-methods.html#standalone-installers). You will have a file named `rust-1.63.0-x86_64-unknown-linux-gnu.tar.gz` downloaded (version 1.63.0 is the latest stable version as of Sep 10, 2022).
## 2. Upload the tarball file to DETER
You can upload the file using `scp`. We will upload it to the `$HOME` directory for this example.
```bash
scp ./rust-1.63.0-x86_64-unknown-linux-gnu.tar.gz <USERNAME>@users.isi.deterlab.net:~
```
## 3. SSH to your machine and extract the tarball file
First, SSH into DETER, and ssh to your machine from there. Then, extract the tarball file by running the following command. This may take some minutes.
```bash
tar -xf rust-1.63.0-x86_64-unknown-linux-gnu.tar.gz
```
This will create a directory named `rust-1.63.0-x86_64-unknown-linux-gnu` in `$HOME`.
## 4. Run the install script
Run the install script. This may also take a couple of minutes to finish.
```bash
cd rust-1.63.0-x86_64-unknown-linux-gnu
sudo ./install.sh
```
This script will install the following components:
- rustc (Compiler)
- rust-std-x86_64-unknown-linux-gnu (Standard Library)
- rust-docs (Document Generator)
- rust-demangler-preview
- cargo (Package Manager)
- rustfmt-preview (Formatter)
- rls-preview
- llvm-tools-preview
- clippy-preview (Linter)
- rust-analysis-x86_64-unknown-linux-gnu
**At this point, you will have most of the tools you need to run a Rust program.**
## 5. Export RUSTFLAGS environment variable
We need to set an environment variable `RUSTFLAGS="-L <path-to-rust-std-lib>"`.
We need to tell the Rust compiler where the Rust standard library is located. We can do this by setting an environment variable named `RUSTFLAGS`. When `RUSTFLAGS` is set, cargo will pass this value to every rust compiler invocation.
The tarball file comes with the Rust standard library. After running the `install.sh` script, the standard library is located at `rust-1.63.0-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib`.
If you are using bash, you can set this value by adding the following line to `$HOME/.bash_profile`.
```bash
export RUSTFLAGS="-L $HOME/rust-1.63.0-x86_64-unknown-linux-gnu/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib"
```
Don’t forget to source the file!
```bash
source ~/.bash_profile
```
Now you can build your Rust project with `cargo`.
```
cd <your-project>
cargo build --release
```