The first step to learn something new is to download and install. I personally work with multiple operating systems, including OSX, Windows, and Linux. I will note the differences for the different environments.
OSX
There are packages for homebrew and macports, but since rust is still a fairly fast moving project I decided not to use these and instead use rustup.
Linux
Again, most of the Linux distributions have a rust package available and for production environments where stability is key. Again for the purposes of my learning here, I have decided to use rustup.
Windows
The standard rustup setup is a shell script, so that will not work for windows. However looking at the Cargo installation page there is a link for a windows installer rustup-init.exe. This installer basically works the same as the rustup script. It installs in your home directory under .cargo.
rustup
The standard way to install is using the rustup url below and piping it though the shell.
curl https://sh.rustup.rs -sSf | sh
Now that we have installed rust, what does that mean, where is it installed, and what go installed. The installation is by default your home directory in the .cargo directory. Several developer tools are installed, but the ones that I will focus on are rustup and cargo.
.cargo
.cargo/bin
.cargo/bin/rls
.cargo/bin/rustdoc
.cargo/bin/cargo
.cargo/bin/rust-lldb
.cargo/bin/cargo-clippy
.cargo/bin/rustc
.cargo/bin/cargo-fmt
.cargo/bin/rustup
.cargo/bin/rustfmt
.cargo/bin/rust-gdb
.cargo/env
The rustup command is the one stop shop for your local rust environment. You can switch to a different channel to get beta or nightly updates. You can update current channels to the latest. You can add cross compile targets. Basically anything related the development tools can be managed through this command.
$rustup
rustup 1.16.0 (beab5ac2b 2018-12-06)
The Rust toolchain installer
USAGE:
rustup [FLAGS] <SUBCOMMAND>
FLAGS:
-v, --verbose Enable verbose output
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
show Show the active and installed toolchains
update Update Rust toolchains and rustup
default Set the default toolchain
toolchain Modify or query the installed toolchains
target Modify a toolchain's supported targets
component Modify a toolchain's installed components
override Modify directory toolchain overrides
run Run a command with an environment configured for a given toolchain
which Display which binary will be run for a given command
doc Open the documentation for the current toolchain
man View the man page for a given command
self Modify the rustup installation
set Alter rustup settings
completions Generate completion scripts for your shell
help Prints this message or the help of the given subcommand(s)
DISCUSSION:
rustup installs The Rust Programming Language from the official
release channels, enabling you to easily switch between stable,
beta, and nightly compilers and keep them updated. It makes
cross-compiling simpler with binary builds of the standard library
for common platforms.
If you are new to Rust consider running `rustup doc --book` to
learn Rust.
Examples
# List the toolchain versions available
rustup toolchain list
# Install the beta channel
rustup toolchain install beta
# Install the nightly channel
rustup toolchain install beta
# Make the nightly channel the default
rustup default nightly
# Make sure that rustup has been updated
rustup self update
# Make sure all of the channels have been update to latest
rustup update
Cargo
Cargo is your build and dependency management tool. Think of it like npm or maven. There are repositories of “crates”, that are thirdparty libraries.
$cargo init --help
cargo-init
Create a new cargo package in an existing directory
USAGE:
cargo init [OPTIONS] [--] [path]
OPTIONS:
--registry <REGISTRY> Registry to use
--vcs <VCS> Initialize a new repository for the given version control system (git, hg, pijul, or
fossil) or do not initialize any version control at all (none), overriding a global
configuration. [possible values: git, hg, pijul, fossil, none]
--bin Use a binary (application) template [default]
--lib Use a library template
--edition <YEAR> Edition to set for the crate generated [possible values: 2015, 2018]
--name <NAME> Set the resulting package name, defaults to the directory name
-v, --verbose Use verbose output (-vv very verbose/build.rs output)
-q, --quiet No output printed to stdout
--color <WHEN> Coloring: auto, always, never
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date
-Z <FLAG>... Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details
-h, --help Prints help information
ARGS:
<path> [default: .]
Examples
# Create an empty binary project in the current directory
cargo init
# Create an empty library project in the current directory
cargo init --lib
# Create an empty library in a new my-library directory
cargo init --lib my-library
Conclusions
The rust development environment is easy to configure and update. Cargo makes dependency management straight forward and makes the language very approachable if you have experience with npm or another package manager. In the next post, I will start actually coding and will discuss cargo in more detail. If you have any questions or corrections, please send them to @rushtonality.