Как установить язык программирования Rust на Linux

by itisgood
Rust – это универсальный, мультипарадигмальный, современный, кроссплатформенный и системный язык программирования с открытым исходным кодом, спонсируемый Mozilla Research.
Он был разработан для достижения таких целей, как безопасность, скорость и параллелизм.
Rust синтаксически похож на C ++, [14], но его разработчики намерены обеспечить лучшую безопасность памяти при сохранении производительности.
В настоящее время Rust используется во многих организациях, таких как Firefox, Chef, Dropbox, Oracle, GNOME и т. д.

Как установить Runs в Linux?

Существует множество способов установки 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

Запустите следующую команду для настройки вашей текущей оболочки.

$ 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

Создайте файл, добавьте приведенный ниже код и сохраните файл.

Убедитесь, что файлы Rust всегда заканчиваются расширением .rs.

$ vi 2g.rs

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

Запустите следующую команду, чтобы скомпилировать код rust

$ rustc 2g.rs

Приведенная выше команда создаст исполняемый файл программы 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, чтобы получить вывод.

$ ./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)

Выполните следующую команду, чтобы удалить пакет Rust из вашей системы.

$ rustup self uninstall

После удаления пакета Rust удалите каталог проекта Rust.

$ rm -fr ~/projects

 

You may also like

Leave a Comment