GNU/Linux >> Linux の 問題 >  >> Linux

RockyLinux8にRustプログラミング言語をインストールする方法

Rustは、Mozillaによって開発された無料のオープンソースサーバーサイドプログラミング言語です。これは主に、速度、メモリの安全性、およびC /C++などの低レベルのコーディング言語の置き換えに重点を置いていました。ゲームエンジン、オペレーティングシステム、ファイルシステム、ブラウザコンポーネントなど、さまざまなアプリケーションを作成するために使用されます。組み込みデバイスで実行でき、他の言語と簡単に統合できます。

この投稿では、Rustプログラミング言語をRockyLinux8にインストールする方法を紹介します。

前提条件

  • Atlantic.NetクラウドプラットフォームでRockyLinux8を実行しているサーバー
  • サーバーで構成されているrootパスワード

ステップ1-Atlantic.Netクラウドサーバーを作成する

まず、Atlantic.Netクラウドサーバーにログインします。 2GB以上のRAMを搭載したオペレーティングシステムとしてRockyLinux8を選択して、新しいサーバーを作成します。 SSH経由でクラウドサーバーに接続し、ページの上部で強調表示されているクレデンシャルを使用してログインします。

サーバーにログインしたら、次のコマンドを実行して、ベースシステムを最新の利用可能なパッケージで更新します。

dnf update -y

ステップ2–必要な依存関係をインストールする

まず、サーバーにいくつかの必要な依存関係をインストールする必要があります。次のコマンドを実行して、それらすべてをインストールできます。

dnf install epel-release -y
dnf install cmake gcc make curl clang -y

すべての依存関係がインストールされたら、次のステップに進むことができます。

ステップ3– RockyLinux8にRustをインストールする

次に、次のコマンドを実行して、Rustインストールスクリプトをダウンロードして実行します。

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

以下に示すように、インストールオプションを選択するように求められます。

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

1と入力し、Enterキーを押してインストールを開始します。インストールが完了すると、次の出力が表示されます。

  stable-x86_64-unknown-linux-gnu installed - rustc 1.56.0 (09c42c458 2021-10-18)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source $HOME/.cargo/env

次に、次のコマンドを使用してRustシステムパス変数をアクティブにします。

source ~/.profile
source ~/.cargo/env

次に、次のコマンドを使用してRustのバージョンを確認します。

rustc -V

次の出力にRustバージョンが表示されます。

rustc 1.56.0 (09c42c458 2021-10-18)

ステップ4–Rustアプリケーションを作成する

この時点で、Rustがインストールされています。それでは、Rustをテストするためのサンプルアプリケーションを作成しましょう。

まず、次のコマンドを使用してprojectという名前のディレクトリを作成します。

mkdir project

次に、ディレクトリをプロジェクトに変更し、次のコマンドを使用してサンプルのRustアプリケーションを作成します。

cd project
nano helloworld.rs

次のコードを追加します:

fn main() {
    println!("This is my first project created using rust!");
}

ファイルを保存して閉じ、次のコマンドを使用してプログラムをコンパイルします。

rustc helloworld.rs

このコマンドは、現在のディレクトリに実行可能ファイルを作成します。

次に、次のコマンドを使用してプログラムを実行します。

./helloworld

次の出力が表示されます。

This is my first project created using rust!

ステップ5–Rustを最新バージョンに更新する

Rustの最新バージョンを使用することは常に良い考えです。次のコマンドで更新できます:

rustup update

ステップ6–Rustをアンインストールする方法

システムからRustを削除する場合は、次のコマンドを実行します。

rustup self uninstall

アンインストールが正常に完了すると、次の出力が表示されます。

Thanks for hacking in Rust!

This will uninstall all Rust toolchains and data, and remove
$HOME/.cargo/bin from your PATH environment variable.

Continue? (y/N) y

info: removing rustup home
info: removing cargo home
info: removing rustup binaries
info: rustup is uninstalled

結論

上記の投稿では、Rustプログラミング言語をRocky Linux 8にインストールする方法を説明しました。また、Rustを使用してサンプルアプリケーションを作成します。これで、Rust言語を使用してアプリケーションの作成を開始できます。 Atlantic.NetのVPSでRustを使用してみてください!


Linux
  1. RockyLinux8.4のインストール方法

  2. RockyLinux8にNginxを使用してModSecurityをインストールする方法

  3. RockyLinux8にGulp.jsをインストールする方法

  1. LinuxにRustプログラミング言語をインストールする

  2. LinuxにNimプログラミング言語をインストールする方法

  3. LinuxにGo言語をインストールする方法

  1. LinuxにRacketプログラミング言語をインストールする

  2. AlpineLinuxにGoプログラミング言語をインストールする方法

  3. Rustプログラミング言語をFedoraにインストールする方法34/35