Installing Rust

本文详细介绍了如何在CentOS 7上安装Rust编程语言,并通过解决环境变量配置问题确保安装成功。同时,还展示了如何编写并运行第一个Rust程序。

1.官方说明

If you're on Linux or a Mac, all you need to do is this (note that you don't need to type in the $s, they just indicate the start of each command):

  curl -s https://static.rust-lang.org/rustup.sh | sudo sh

2.我的环境:

  Centos 7.0 64位

  ①执行命令:curl -s https://static.rust-lang.org/rustup.sh | sudo sh

 

  ②安装完毕,提示 :

  

     LD_LIBRARY_PATH:Linux环境变量名,该环境变量主要用于指定查找共享库(动态链接库)时除了默认路径之外的其他路径。(该路径在默认路径之前查找)

  移植程序时的经常碰到需要使用一些特定的动态库,而这些编译好的动态库放在我们自己建立的目录里,这时可以将这些目录设置到LD_LIBRARY_PATH中。

    当执行函数动态链接.so时,如果此文件不在缺省目录下‘/lib’ and ‘/usr/lib’.

  那么就需要指定 环境变量 LD_LIBRARY_PATH

  ③If you've got Rust installed, you can open up a shell, and type this:

   rustc --version

  报error啦

  ④解决方案:配置LD_LIBRARY_PATH

    a.vim /etc/ld.so.conf

    b.添加一行代码

     /usr/local/lib

    c.以root身份登录执行命令

     ldconfig -v

  ⑤再查看版本

  rustc --version

  

  OK,到此rust安装成功。

3.编写第一个rust程序并编译执行

  a.vim test.rs 

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

   b. ls 查看文件

     

  c. 编译

  执行命令:rustc test.rs

    

  生成一个二进制文件test

  d.执行可执行文件test

    执行命令:./test

  e.运行结果

    

 

 

 

 

转载于:https://www.cnblogs.com/ifeelo/p/4209632.html

× Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [23 lines of output] Python reports SOABI: cp313-win32 Computed rustc target triple: i686-pc-windows-msvc Installation directory: C:\Users\Administrator\AppData\Local\puccinialin\puccinialin\Cache Rustup already downloaded Installing rust to C:\Users\Administrator\AppData\Local\puccinialin\puccinialin\Cache\rustup warn: It looks like you have an existing rustup settings file at: warn: C:\Users\Administrator\.rustup\settings.toml warn: Rustup will install the default toolchain as specified in the settings file, warn: instead of the one inferred from the default host triple. warn: installing msvc toolchain without its prerequisites info: profile set to 'minimal' info: default host triple is x86_64-pc-windows-msvc warn: Updating existing toolchain, profile choice will be ignored info: syncing channel updates for 'stable-x86_64-pc-windows-msvc' info: default toolchain set to 'stable-x86_64-pc-windows-msvc' Checking if cargo is installed Cargo, the Rust package manager, is not installed or is not on PATH. This package requires Rust and Cargo to compile extensions. Install it through the system's package manager or via https://rustup.rs/ Checking for Rust toolchain.... Rust not found, installing into a temporary directory [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
08-10
Looking in indexes: https://pypi.python.org/simple Collecting cryptography Using cached cryptography-45.0.6.tar.gz (744 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [22 lines of output] Python reports SOABI: cp313t-win_amd64 Computed rustc target triple: x86_64-pc-windows-msvc Installation directory: C:\Users\awei006\AppData\Local\puccinialin\puccinialin\Cache Rustup already downloaded Installing rust to C:\Users\awei006\AppData\Local\puccinialin\puccinialin\Cache\rustup warn: It looks like you have an existing rustup settings file at: warn: C:\Users\awei006\.rustup\settings.toml warn: Rustup will install the default toolchain as specified in the settings file, warn: instead of the one inferred from the default host triple. info: profile set to 'minimal' info: default host triple is x86_64-pc-windows-msvc warn: Updating existing toolchain, profile choice will be ignored info: syncing channel updates for 'stable-x86_64-pc-windows-msvc' info: default toolchain set to 'stable-x86_64-pc-windows-msvc' Checking if cargo is installed Cargo, the Rust package manager, is not installed or is not on PATH. This package requires Rust and Cargo to compile extensions. Install it through the system's package manager or via https://rustup.rs/ Checking for Rust toolchain.... Rust not found, installing into a temporary directory [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
08-28
Looking in indexes: https://pypi.python.org/simple Collecting cryptography Downloading cryptography-45.0.6.tar.gz (744 kB) ---------------------------------------- 744.9/744.9 kB 3.2 MB/s 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [37 lines of output] Python reports SOABI: cp313t-win_amd64 Computed rustc target triple: x86_64-pc-windows-msvc Installation directory: C:\Users\awei006\AppData\Local\puccinialin\puccinialin\Cache Downloading rustup-init from https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe Checking for Rust toolchain.... Rust not found, installing into a temporary directory Downloading rustup-init: 0%| | 0.00/13.6M [00:00<?, ?B/s] Downloading rustup-init: 1%|▏ | 197k/13.6M [00:00<00:06, 1.94MB/s] Downloading rustup-init: 3%|▎ | 393k/13.6M [00:00<00:07, 1.66MB/s] Downloading rustup-init: 7%|▋ | 934k/13.6M [00:00<00:03, 3.21MB/s] Downloading rustup-init: 17%|█▋ | 2.30M/13.6M [00:00<00:01, 7.10MB/s] Downloading rustup-init: 31%|███ | 4.21M/13.6M [00:00<00:00, 11.2MB/s] Downloading rustup-init: 40%|███▉ | 5.37M/13.6M [00:00<00:00, 10.3MB/s] Downloading rustup-init: 60%|██████ | 8.15M/13.6M [00:00<00:00, 15.5MB/s] Downloading rustup-init: 75%|███████▍ | 10.1M/13.6M [00:00<00:00, 16.3MB/s] Downloading rustup-init: 87%|████████▋ | 11.8M/13.6M [00:01<00:00, 10.9MB/s] Downloading rustup-init: 97%|█████████▋| 13.1M/13.6M [00:01<00:00, 7.07MB/s] Downloading rustup-init: 100%|██████████| 13.6M/13.6M [00:01<00:00, 8.79MB/s] Installing rust to C:\Users\awei006\AppData\Local\puccinialin\puccinialin\Cache\rustup info: profile set to 'minimal' info: default host triple is x86_64-pc-windows-msvc info: syncing channel updates for 'stable-x86_64-pc-windows-msvc' info: latest update on 2025-08-07, rust version 1.89.0 (29483883e 2025-08-04) info: downloading component 'cargo' info: downloading component 'rust-std' info: downloading component 'rustc' info: installing component 'cargo' info: installing component 'rust-std' info: installing component 'rustc' info: default toolchain set to 'stable-x86_64-pc-windows-msvc' Checking if cargo is installed Cargo, the Rust package manager, is not installed or is not on PATH. This package requires Rust and Cargo to compile extensions. Install it through the system's package manager or via https://rustup.rs/ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
08-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值