Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Quick links: redhat.com, Customer Portal, Red Hat's developer site, Red Hat's partner site.

  • You are here

    Red Hat

    Learn about our open source products, services, and company.

  • You are here

    Red Hat Customer Portal

    Get product support and knowledge from the open source experts.

  • You are here

    Red Hat Developer

    Read developer tutorials and download Red Hat software for cloud application development.

  • You are here

    Red Hat Partner Connect

    Get training, subscriptions, certifications, and more for partners to build, sell, and support customer solutions.

Products & tools

  • Ansible.com

    Learn about and try our IT automation product.
  • Red Hat Ecosystem Catalog

    Find hardware, software, and cloud providers―and download container images―certified to perform with Red Hat technologies.

Try, buy, & sell

  • Red Hat Hybrid Cloud Console

    Access technical how-tos, tutorials, and learning paths focused on Red Hat’s hybrid cloud managed services.
  • Red Hat Store

    Buy select Red Hat products and services online.
  • Red Hat Marketplace

    Try, buy, sell, and manage certified enterprise software for container-based environments.

Events

  • Red Hat Summit and AnsibleFest

    Register for and learn about our annual open source IT industry event.

Hello World - installing Rust on RHEL 7

February 13, 2019
Related topics:
Linux
Related products:
Red Hat Enterprise Linux

Share:

Share on twitter Share on facebook Share on linkedin Share with email
  • Introduction and Prerequisites
  • 1. Enable necessary software repositories
  • 2. Setup your development environment
  • 3. Hello World and your first Rust application
  • Working with Software Collection packages
  • Troubleshooting and FAQ
Introduction and Prerequisites

Introduction and Prerequisites

In this tutorial, you will install the Rust 1.31 Toolset and build a simple Rust Hello World application. This tutorial should take less than 30 minutes to complete.

Before you begin, you will need a current Red Hat Enterprise Linux 7 workstation or server subscription that allows you to download software and get updates from Red Hat. If you don’t have an active subscription, register and obtain the Red Hat Developer subscription (includes RHEL server) from here.

NOTE: The Rust Compiler naming convention has changed so that the version number reflects the community version. The previous version was Rust-toolset-7 which was based on Rust 1.29.

If you encounter difficulties at any point, see Troubleshooting and FAQ.

1. Enable necessary software repositories

1. Enable necessary software repositories

In this step, you will configure and “register” your system to obtain software from the devtools repository by using the command line interface. 

Note: registering a subscription (the steps to follow) is different than registering for the Red Hat Developer Program (which you’ve likely done by now).

You can add or remove software repositories from the command line using the subscription-manager tool as the root user. Use the --list option to view the available software repositories and verify that you have access to the devtools repo.

$ su -
# subscription-manager repos --list | egrep devtools

If you don’t see any devtools repositories in the list, your subscription might not include it. See Troubleshooting and FAQ for more information.

If you are using a desktop edition of Red Hat Enterprise Linux, change -server- to -desktop- in the following commands:

# subscription-manager repos --enable rhel-7-server-devtools-rpms
# subscription-manager repos --enable rhel-server-rhscl-7-rpms

Add the Red Hat Developer Tools key to your system:

# cd /etc/pki/rpm-gpg
# wget -O RPM-GPG-KEY-redhat-devel https://www.redhat.com/security/data/a5787476.txt
# rpm --import RPM-GPG-KEY-redhat-devel
2. Setup your development environment

2. Setup your development environment

In this next step you will use a single command to download the Rust compiler. The length of time this step takes depends on the speed of your Internet connection and your system. With a reasonably fast connection, this step should complete in well under 5 minutes.

$ su -
# yum install rust-toolset-1.31


In Rust Toolset, cargo is provided by the rust-toolset-1.31-cargo package and is automatically installed with the rust-toolset-1.31 package.

3. Hello World and your first Rust application

3. Hello World and your first Rust application

Create and run the sample C++ Hello World projects

The following steps will create and run a Rust Hello World project

Using Rust from the command line

The Rust compiler (rustc) is not usually invoked directly, but through the cargo tool, like cargo build. You need to add Rust to your environment with scl enable in a Terminal window.

$ scl enable rust-toolset-1.31 bash

The simplest way to get started with a new project is using cargo new.  Create a hello executable project using “cargo new --bin hello”.  This will create a new directory with a Cargo.toml project manifest and the src/main.rs entry point for your program.

hello/Cargo.toml
   [package]
   name = "hello"
   version = "0.1.0"
   authors = ["I.M Coder <imc@redhat.com>"]

   [dependencies]

hello/src/main.rs
   fn main() {
       println!("Hello, world!");
   }

Now compile and run the program:

$ cd hello
$ cargo run
Hello, world!

Let’s customize that message.  Edit src/main.rs using a text editor such as vi, nano, or gedit, changing to the following content:

fn main() {
">println!("Hello, Red Hat Developer Program World!");
}

When making changes it’s often useful to get quick feedback from the compiler that your code will be accepted.  You can run cargo check for full syntax and type checking, without the longer delays for code generation.  Then when you’re ready, compile and run it again.

$ cargo run
Hello, Red Hat Developer Program World!
Working with Software Collection packages

Working with Software Collection packages

These tools are packaged as software collections which  are designed to allow multiple versions of software to be installed concurrently. To accomplish this, the desired package is added to your runtime environment as needed with the scl enable command. When scl enable runs, it modifies environment variables and then runs the specified command. The environmental changes only affect the command that is run by scl and any processes that are run from that command. The steps in this tutorial run the command bash to start a new interactive shell to work in the updated environment. The changes aren’t permanent. Typing exit will return to the original shell with the original environment. Each time you login, or start a new terminal session, scl enable needs to be run again.

While it is possible to change the system profile to make RHSCL packages part of the system’s global environment, this is not recommended. Doing this can cause conflicts and unexpected problems with other applications because the system version of the package is obscured by having the RHSCL version in the path first.

Learn more about Red Hat Software Collections

Red Hat Software Collections deliver the latest stable versions of dynamic languages, open source databases, and web development tools that can be deployed alongside those included in Red Hat Enterprise Linux. Red Hat Software Collections is available with select Red Hat Enterprise Linux subscriptions and has a three-year life cycle to allow rapid innovation without sacrificing stability. For more information:

  • Red Hat Software Collections Packaging Guide — The packaging guide for Red Hat Software Collections explains the concept of software collections, documents the scl utility, and provides a detailed explanation of how to create a custom software collection or extend an existing one.

  • Red Hat Software Collections Release Notes — The release notes for Red Hat Software Collections document known problems, possible issues, and other important information available at the time of release of the content set. They also contain useful information on installing, rebuilding, and migrating.

  • How to use Red Hat Software Collections (RHSCL), Red Hat Developer Subscriptions, or Clang/LLVM, Go, Rust compilers — This article lists which Red Hat Enterprise Linux subscriptions include access to Red Hat Software Collections, Developer Toolset (with GCC), Clang/LLVM, Go, and Rust.

You can view the list of packages available in RHSCL by running:

$ yum --disablerepo="*" --enablerepo="rhel-server-rhscl-7-rpms" list available

Developing with Red Hat Enterprise Linux

Red Hat Enterprise Linux 7 Developer Guide — The developer guide for Red Hat Enterprise Linux 7 provides an introduction to application development tools and using source code management tools such as Git in Red Hat Enterprise Linux 7.

Become a Red Hat developer and join the Red Hat Developer Program

Red Hat delivers the resources and ecosystem of experts to help you be more productive and build great solutions. Register for free at developers.redhat.com.

 

Troubleshooting and FAQ

Troubleshooting and FAQ

  1. As a developer, how can I get a Red Hat Enterprise Linux subscription that includes the Clang/LLVM, Go, or Rust Compilers?

Developers can get a no-cost Red Hat Enterprise Linux Developer subscription for development purposes by registering and downloading through developers.redhat.com. We recommend you follow our Getting Started Guide which covers downloading and installing Red Hat Enterprise Linux on a physical system or virtual machine (VM) using your choice of VirtualBox, VMware, Microsoft Hyper-V, or Linux KVM/Libvirt. For more information, see Frequently asked questions: no-cost Red Hat Enterprise Linux Developer subscription.

  1. I can’t find the devtools or RHSCL repository on my system.

Some Red Hat Enterprise Linux subscriptions do not include access to Software Collections or development tools. For a list of what subscriptions are included see How to use Red Hat Software Collections (RHSCL), Red Hat Developer Toolset (DTS, etc.).

The name of the repository depends on whether you have a server or workstation version of Red Hat Enterprise Linux installed. You can use subscription-manager to view the available software repositories and verify that you have access to RHSCL and devtools:

$ su -
# subscription-manager repos --list | egrep rhscl
# subscription-manager repos --list | egrep devtools

 

  1. When I run yum install package (go-toolset-7, llvm-toolset-7, rust-toolset-7), it fails due to a missing dependency.

Some software collections require packages that are in the devtools RPMs repository, which is not enabled by default. See Step 1 above, for how to enable both the applicable RPMs and repositories.

  1. How can I view the Go manual pages?

The Go compiler help command provides information on its usage. To show the help index:

$ scl enable go-toolset-7 'go help'
  1. How can I find out what RHSCL packages are installed?

scl --list will show the list of RHSCL packages that have been installed, whether they are enabled or not.

$ scl --list
Last updated: July 11, 2024
Red Hat Developers logo LinkedIn YouTube Twitter Facebook

Products

  • Red Hat Enterprise Linux
  • Red Hat OpenShift
  • Red Hat Ansible Automation Platform

Build

  • Developer Sandbox
  • Developer Tools
  • Interactive Tutorials
  • API Catalog

Quicklinks

  • Learning Resources
  • E-books
  • Cheat Sheets
  • Blog
  • Events
  • Newsletter

Communicate

  • About us
  • Contact sales
  • Find a partner
  • Report a website issue
  • Site Status Dashboard
  • Report a security problem

RED HAT DEVELOPER

Build here. Go anywhere.

We serve the builders. The problem solvers who create careers with code.

Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

Sign me up

Red Hat legal and privacy links

  • About Red Hat
  • Jobs
  • Events
  • Locations
  • Contact Red Hat
  • Red Hat Blog
  • Inclusion at Red Hat
  • Cool Stuff Store
  • Red Hat Summit

Red Hat legal and privacy links

  • Privacy statement
  • Terms of use
  • All policies and guidelines
  • Digital accessibility

Report a website issue