Installation fuel node

17 Feb 2023


Install Rust and Cargo

The easiest way to get Cargo is to install the current stable release of Rust by using rustup. Installing Rust using rustup will also install cargo.
On Linux and macOS systems, this is done as follows:

curl -sSf | sh

It will download a script, and start the installation. If everything goes well, you’ll see this appear:

Rust is installed now. Great!

On Windows, download and run rustup-init.exe. It will start the installation in a console and present the above message on success.
After this, you can use the rustup command to also install beta or nightly channels for Rust and Cargo.
For other installation options and information, visit the install page of the Rust website.

Build and Install Cargo from Source

Alternatively, you can build Cargo from source.

First Steps with Cargo

This section provides a quick sense for the cargo command line tool. We demonstrate its ability to generate a new package for us, its ability to compile the crate within the package, and its ability to run the resulting program.
To start a new package with Cargo, use cargo new:

$ cargo new hello_world

Cargo defaults to --bin to make a binary program. To make a library, we would pass --lib, instead.
Let’s check out what Cargo has generated for us:

$ cd hello_world
$ tree .
├── Cargo.toml
└── src

1 directory, 2 files

This is all we need to get started. First, let’s check out Cargo.toml:

name = "hello_world"
version = "0.1.0"
edition = "2021"


This is called a manifest, and it contains all of the metadata that Cargo needs to compile your package.
Here’s what’s in src/

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

Cargo generated a “hello world” program for us, otherwise known as a binary crate. Let’s compile it:

$ cargo build
   Compiling hello_world v0.1.0 (file:///path/to/package/hello_world)

And then run it:

$ ./target/debug/hello_world
Hello, world!

We can also use cargo run to compile and then run it, all in one step:

$ cargo run
     Fresh hello_world v0.1.0 (file:///path/to/package/hello_world)
   Running `target/hello_world`
Hello, world!

Going further

For more details on using Cargo, check out the Cargo Guide

Write & Read to Earn with BULB

Learn More

Enjoy this blog? Subscribe to berlinneverdie


No comments yet.