Complete Guide To Install Rust & Scrypto on MacOS

Radix has created a fantastic tool for anyone to create decentralized apps through Scrypto! But it may be challenging to get started if you are new to coding. That is why I made this guide to help you with the basics and installation of all the prerequisites!

After following this guide, you will have installed all the prerequisites to code on Rust & Scrypto.

  1. Install Visual Studio Code
  2. Install Rust Analyzer
  3. Install Rust
  4. Install C/C++ for Visual Studio Code
  5. Install Clang
  6. Enable Cargo
  7. Add WebAssembly Target
  8. Install Scrypto Simulator And Command-line Tools
  9. Create The Hello World Program on Rust

You should know that I’m using macOS Monterey (version 12.4).

This is also the 1st guide in our learning series on learning Rust on macOS. The learning series will equip you with a complete guide on how to learn Rust and later on, Scrypto.

Download and Install Visual Studio Code and Rust Analyzer

1. Download and install Visual Studio Code from the official website. You should download the Mac Universal Stable Build version.

2. Install the rust-analyzer from the official website. Click on Install, and it should launch the Visual Studio code app.

3. Click on Install, and you’re done with this step.

Install C/C++ for Visual Studio Code

1. Install C/C++ for Visual Studio Code from the official website. Click on Install, and it should launch the Visual Studio code app.

2. Click on Install, and you’re done with this step.

Install Clang

Next, you’ll need to make sure Clang is installed.

1. Open the terminal app, key in the command below, and press enter.

clang --version

2. An installer will pop up, and click on Install and accept the license terms. Your mac will now download and install Clang.

If the pop-up does not appear, run this command instead.

xcode-select --install

If it still doesn’t pop up, you’ll need to reboot your mac and try this step again.

The installation may take a while. Click Done, and you’ve installed Clang successfully.

If you run clang –version again, you should get something similar to the screenshot below, which signifies that Clang is installed!

Enable Cargo

1. To enable cargo, run source $HOME/.cargo/env on the terminal.

source $HOME/.cargo/env

Add WebAssembly Target

1. To add the WebAssembly target, run the code below on the terminal.

rustup target add wasm32-unknown-unknown

Install Simulator And Command-line Tools

1. To install the simulator and command-line tools, run the script below on the terminal.

git clone https://github.com/radixdlt/radixdlt-scrypto.git
cd radixdlt-scrypto
cargo install --path ./simulator

It may take a while to install. You can close the terminal once the second screen pops up.

2. To ensure you’ve successfully installed Scrypto, run the command below on the terminal.

scrypto --version

If the terminal shows the version of scrypto, you’ve successfully installed it. At the time of writing, the latest version is scrypto 0.4.1.

Create Hello World Program

Now that you’ve got everything installed, it’s time to test your installation by creating your first program. The guide is based on The Rust Programming Language book.

1. Create a folder anywhere on your mac, or you can follow me and create the folder under documents. You can open Finder, go to Documents, and create a new folder. Let’s call it Scrypto.

2. Within the Scrypto folder, create another folder called helloworld.

3. Launch Visual Studio Code, navigate to the Explorer icon on the top left, and click on Open Folder.

4. Navigate to the folder created earlier, and click on Add.

5. Refer to the screenshot below and click the New File icon. Key in main.rs in the text box and press enter.

6. Key the following code into the middle page. I recommend you type them out instead of copy-pasting to get a better feel of programming. Once completed, save the file by pressing Command+S. You’ll know it’s saved when the “UNSAVED” word in the screenshot below disappears. Anytime you make a change, and it’s not saved, the “UNSAVED” indicator will be there.

fn main() {
println!("Hello, world!");
}

7. Now open the terminal within Visual Studio by clicking on Terminal, then click New Terminal.

8. Now, you need to compile your program. At the terminal at the bottom, type the code below and press enter.

rustc main.rs

9. Now it’s time to run your program. Type in the code below and press enter. This step will execute the Hello World program that you created. If you are successful, you will see “Hello, world!” as shown in the screenshot below. Congratulations, you’re now a #rustacean!

./main

When you’re ready to move to the next step, click the 2nd article to continue with your journey of learning Rust and Scrypto on your mac!

Recent Posts