Introduction
Rust
A language empowering everyone to build reliable and efficient software.
Why Rust?
Performance
Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.
Reliability
Rust’s rich type system and ownership model guarantee memory-safety and thread-safety — enabling you to eliminate many classes of bugs at compile-time.
Productivity
Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi-editor support with auto-completion and type inspections, an auto-formatter, and more.
Rust can run on a great number of platforms and used in production by companies/organizations such as Dropbox, CoreOS, NPM and many more.
Install Rust
install rust by running the following command in your terminal, and follow the onscreen instructions. Note that rust actually installed as well as managed by the rustup tool.
[root@unixcop ~]# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Welcome to Rust!
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
/root/.rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory located at:
/root/.cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
/root/.cargo/bin
This path will then be added to your PATH environment variable by
modifying the profile files located at:
/root/.profile
/root/.bash_profile
/root/.bashrc
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1
Once the Rust installation is complete, the Cargo’s bin directory (~/.cargo/bin – where all tools are installed) will be added in your PATH environment variable, in ~/.profile.
During the installation rustup will attempt to add the cargo’s bin directory to your PATH; if this fails for one reason or another, do it manually to get started with using rust with :
# vim /root/.profile
And add this line manually
export PATH="$HOME/.cargo/bin:$PATH"
Configure your current shell to work with the rust environment by running these commands.
# source ~/.profile
# source ~/.cargo/env
Finally Verify the version of installed Rust with:
[root@unixcop ~]# rustc --version
rustc 1.54.0 (a178d0322 2021-07-26)
[root@unixcop ~]#
Try Rust Programming Language
Now Rust installed on your system, you can test it by creating your first rust program as follows. Begin by making a directory where your program files will reside.
# mkdir test
# cd test
Create a file called unixcop.rs
# vim unixcop.rs
Copy and paste the following lines of code to the file.
fn main() {
println!("Hello Visitors, it's uNiXcOp.com ,The best Linux guide on the Internet!....This is a new project with Rust");
}
Save the file and create an executable called unixcop in the current directory with:
# rustc unixcop.rs
Excute it with :
# ./unixcop
Conclusion
So we have explained how to install and use Rust programming language in Linux. enjoy it.