溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux系統(tǒng)如何安裝Rust語言

發(fā)布時間:2022-01-24 10:40:08 來源:億速云 閱讀:222 作者:小新 欄目:開發(fā)技術(shù)

這篇文章主要介紹了Linux系統(tǒng)如何安裝Rust語言,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Rust 速度驚人且內(nèi)存利用率極高。由于沒有運行時和垃圾回收,它能夠勝任對性能要求特別高的服務(wù),可以在嵌入式設(shè)備上運行,還能輕松和其他語言集成。

Rust 語言簡介:

  • Rust 語言是一種高效、可靠的通用高級語言。

  • 其高效不僅限于開發(fā)效率,它的執(zhí)行效率也是令人稱贊的,是一種少有的兼顧開發(fā)效率和執(zhí)行效率的語言。

  • Rust 語言由 Mozilla 開發(fā),最早發(fā)布于 2014 年 9 月。

  • Rust 的編譯器是在 MIT License 和 Apache License 2.0 雙重協(xié)議聲明下的免費開源軟件。

Linux 中安裝 Rust 語言具體步驟:

我們可以通過多種方式安裝 Rust,但以下是官方推薦的安裝方式。

 $ curl https://sh.rustup.rs -sSf | 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. 
 It will add the cargo, rustc, rustup and other commands to Cargo's bin directory, located at: 
   /home/daygeek/.cargo/bin 
 This path will then be added to your PATH environment variable by modifying the profile files located at: 
   /home/daygeek/.profile   /home/daygeek/.bash_profile 
 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   modify PATH variable: yes 
 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation >1 
 info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: latest update on 2018-12-06, rust version 1.31.0 (abe02cefd 2018-12-04) info: downloading component 'rustc'  77.7 MiB /  77.7 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: downloading component 'rust-std'  54.2 MiB /  54.2 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: downloading component 'cargo'   4.7 MiB /   4.7 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: downloading component 'rust-docs'   8.5 MiB /   8.5 MiB (100 %)   1.2 MiB/s ETA:   0 s                 info: installing component 'rustc' info: installing component 'rust-std' info: installing component 'cargo' info: installing component 'rust-docs' info: default toolchain set to 'stable' 
   stable installed - rustc 1.31.0 (abe02cefd 2018-12-04) 
 
 Rust is installed now. Great! 
 To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH environment variable. Next time you log in this will be done automatically. 
 To configure your current shell run source $HOME/.cargo/env

運行以下命令配置當(dāng)前 shell。

 $ source $HOME/.cargo/env

運行以下命令驗證已安裝的 Rust 版本。

 $ rustc --version rustc 1.31.0 (abe02cefd 2018-12-04)

如何測試 Rust 編程語言?

安裝 Rust 后,請按照以下步驟檢查 Rust 語言是否正常工作。

 $ mkdir ~/projects $ cd ~/projects $ mkdir hello_world $ cd hello_world

創(chuàng)建一個文件并添加以下代碼并保存。確保 Rust 文件始終以 .rs 擴(kuò)展名結(jié)尾。

 $ vi 2g.rs 
 fn main() {  println!("Hello, It's 2DayGeek.com - Best Linux Practical Blog!"); }

運行以下命令編譯 rust 代碼。

 $ rustc 2g.rs

上面的命令將在同一目錄中創(chuàng)建一個可執(zhí)行的 Rust 程序。

 $ ls -lh total 3.9M -rwxr-xr-x 1 daygeek daygeek 3.9M Dec 14 11:09 2g -rw-r--r-- 1 daygeek daygeek 86 Dec 14 11:09 2g.rs

運行 Rust 可執(zhí)行文件得到輸出。

 $ ./2g Hello, It's 2DayGeek.com - Best Linux Practical Blog!

好了!正常工作了。

將 Rust 更新到最新版本。

 $ rustup update info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' info: checking for self-updates 
   stable-x86_64-unknown-linux-gnu unchanged - rustc 1.31.0 (abe02cefd 2018-12-04)

運行以下命令從系統(tǒng)中刪除 Rust 包。

 $ rustup self uninstall

卸載 Rust 包后,刪除 Rust 項目目錄。

 $ rm -fr ~/projects

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“Linux系統(tǒng)如何安裝Rust語言”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI