FreeBSD下安装rustup、cargo和uv

在安装mini-racer包的时候,有cargo方面的报错,于是准备安装rustup和cargo。

FreeBSD下安装rust有两种方法,一种是pkg安装:

复制代码
pkg install rust

但是没有找到cargo怎么安装。 尽管pkg search能看到很多cargo库,但是不知道该怎么安装,反正让我把名字全写一遍,我是不干。

复制代码
pkg search cargo
cargo-about-0.6.5_1            Rust: Cargo plugin to generate list of all licenses for a crate
cargo-audit-0.21.0_1,1         Audit Cargo.lock for crates with security vulnerabilities
cargo-bloat-0.12.1_6           Rust: Find out what takes most of the space in your executable
cargo-c-0.10.7_1               Cargo C-ABI helpers
cargo-cache-0.8.3_5            Rust: Manage cargo cache, print sizes of dirs, remove dirs selectively
cargo-deny-0.16.2_1            Rust: Cargo plugin for linting dependencies
cargo-depgraph-1.6.0_10        Rust: Create dependency graphs for cargo projects
cargo-edit-0.13.0_3            Rust: Utility for managing cargo dependencies from the command line
cargo-generate-0.21.0_7        Quickly generate Rust project templates from existing git repositories
cargo-hack-0.6.33_2            Rust: Cargo subcommand for testing and continuous integration
cargo-leptos-0.2.29_2          Build tool for Leptos
cargo-llvm-cov-0.6.15          Rust: Cargo subcommand to easily use LLVM source-based code coverage
cargo-mutants-24.11.0_1        Mutation testing for Rust
cargo-spellcheck-0.14.0_5      Checks documentation for spelling and grammar mistakes
cargo-tarpaulin-0.31.4         Code coverage tool for Rust projects
cargo-udeps-0.1.53             Rust: Find unused dependencies in Cargo.toml

于是就想着按照官方提供的安装方法进行安装。先上结论,安装起来比较慢....

安装rustup

FreeBSD下执行安装命令:

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

输出:

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

info: downloading installer

warning: it looks like you have an existing installation of Rust at:

warning: /usr/local/bin

warning: It is recommended that rustup be the primary Rust installation.

warning: Otherwise you may have confusion unless you are careful with your PATH

warning: If you are sure that you want both rustup and your already installed Rust

warning: then please reply `y' or `yes' or set RUSTUP_INIT_SKIP_PATH_CHECK to yes

warning: or pass `-y' to ignore all ignorable checks.

error: cannot install while Rust is installed

Continue? (y/N) y

Welcome to Rust!

This will download and install the official compiler for the Rust

programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup

home directory, located at:

/home/skywalk/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

/home/skywalk/.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:

/home/skywalk/.cargo/bin

This path will then be added to your PATH environment variable by

modifying the profile file located at:

/home/skywalk/.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-freebsd

default toolchain: stable (default)

profile: default

modify PATH variable: yes

  1. Proceed with standard installation (default - just press enter)

  2. Customize installation

  3. Cancel installation

>

info: profile set to 'default'

info: default host triple is x86_64-unknown-freebsd

info: syncing channel updates for 'stable-x86_64-unknown-freebsd'

安装的有点慢,加上镜像试试。好像也不管用,毕竟还没有到cargo那一层。

速度每秒只有50k左右:

13.9 MiB / 28.3 MiB ( 49 %) 44.8 KiB/s in 4m 53s ETA: 5m 29s

安装完毕显示

stable-x86_64-unknown-freebsd installed - rustc 1.92.0 (ded5c06cf 2025-12-08)

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, you need to source

the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):

. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh

source "$HOME/.cargo/env.fish" # For fish

source "(nu.home-path)/.cargo/env.nu" # For nushell

也就是执行这条命令激活华景

复制代码
. "$HOME/.cargo/env"

尝试安装定制minimal版

准备少装点软件,希望能快一点,等安装好cargo再装其它软件。

执行后,选 2) Customize installation

profile set to 'minimal' ,然后再安装。

安装完成:

info: profile set to 'minimal'

info: setting default host triple to x86_64-unknown-freebsd

info: syncing channel updates for 'stable-x86_64-unknown-freebsd'

821.1 KiB / 821.1 KiB (100 %) 120.2 KiB/s in 7s ETA: 0s

info: latest update on 2025-01-30, rust version 1.84.1 (e71f9a9a9 2025-01-27)

info: downloading component 'cargo'

info: downloading component 'rust-std'

28.3 MiB / 28.3 MiB (100 %) 70.4 KiB/s in 10m 31s ETA: 0s

info: downloading component 'rustc'

76.5 MiB / 76.5 MiB (100 %) 57.6 KiB/s in 27m 51s ETA: 0s

info: installing component 'cargo'

9.3 MiB / 9.3 MiB (100 %) 5.7 MiB/s in 1s ETA: 0s

info: installing component 'rust-std'

28.3 MiB / 28.3 MiB (100 %) 5.2 MiB/s in 5s ETA: 0s

info: installing component 'rustc'

76.5 MiB / 76.5 MiB (100 %) 4.8 MiB/s in 15s ETA: 0s

info: default toolchain set to 'stable-x86_64-unknown-freebsd'

stable-x86_64-unknown-freebsd installed - rustc 1.84.1 (e71f9a9a9 2025-01-27)

Rust is installed now. Great!

To get started you need Cargo's bin directory ($HOME/.cargo/bin) in your PATH

environment variable. This has not been done automatically.

To configure your current shell, you need to source

the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):

. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh

source "$HOME/.cargo/env.fish" # For fish

激活cargo环境

安装好后,使用命令激活cargo环境:

复制代码
. "$HOME/.cargo/env"

现在cargo就能用啦!

这次之所以要装cargo,是为了装mini-racer,后面会进行测试。

为cargo加入镜像

为了cargo更快,设置镜像。

cargo设置镜像跟其它软件不一样,清华源给的镜像命令除了设置镜像,还执行了一次安装指令。

复制代码
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install stable # 

哈哈,这时候就能看到cargo的速度飞快了。

测试装mini-racer

装cargo就是为了能装mini-racer 。在linux下没有这么麻烦,mini-racer很好装。但是FreeBSD下会报错,才有这么多波折。

安装uv库

复制代码
pip install uv

后来发现uv库也pip安装不上,参考这里安装:FreeBSD下安装python的uv库(超快速度: uv比 pip 和 pip-tools (pip-compile 和 pip-sync) 快 10-100 倍。)-CSDN博客

直接用这条命令安装:

复制代码
cargo install --git https://github.com/astral-sh/uv uv

创建uv虚拟环境并安装软件

创建虚拟环境

复制代码
uv venv py311

激活

复制代码
./py311/bin/python ./python311/bin/activate_this.py

安装mini-racer

复制代码
uv pip ill mini-racer

调试

Rust镜像设置为清华源

使用 rustup 安装 rust 时,若要启用镜像源,执行:

复制代码
# for bash
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install stable # for stable
# for fish
env RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install stable # for stable
# for bash
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install nightly # for nightly
# for fish
env RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install nightly # for nightly
# for bash
RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install nightly-YYYY-mm-dd
# for fish
env RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup rustup install nightly-YYYY-mm-dd

若要长期启用镜像源,执行:

复制代码
# for bash
echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup' >> ~/.bash_profile
echo 'export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup' >> ~/.bash_profile
# for fish
echo 'set -x RUSTUP_UPDATE_ROOT https://mirrors.tuna.tsinghua.edu.cn/rustup/rustup' >> ~/.config/fish/config.fish
echo 'set -x RUSTUP_DIST_SERVER https://mirrors.tuna.tsinghua.edu.cn/rustup' >> ~/.config/fish/config.fish

注:rustup 在判断是否需要更新时依赖于 toml 的 sha256,由于 toml 内容中相关链接被替换为镜像源,第一次切换到镜像源时各个 channel 会被认为需要更新。

因为安装速度慢,定制化安装rust最小系统minimal

I'm going to ask you the value of each of these installation options.

You may simply press the Enter key to leave unchanged.

Default host triple? [x86_64-unknown-freebsd]

Default toolchain? (stable/beta/nightly/none) [stable]

Profile (which tools and data to install)? (minimal/default/complete) [minimal]

Modify PATH variable? (Y/n)

n

Current installation options:

default host triple: x86_64-unknown-freebsd

default toolchain: stable

profile: minimal

modify PATH variable: no

  1. Proceed with selected options (default - just press enter)

  2. Customize installation

相关推荐
Java后端的Ai之路5 小时前
【Python 教程15】-Python和Web
python
冬奇Lab6 小时前
一天一个开源项目(第15篇):MapToPoster - 用代码将城市地图转换为精美的海报设计
python·开源
灰子学技术8 小时前
go response.Body.close()导致连接异常处理
开发语言·后端·golang
二十雨辰8 小时前
[python]-AI大模型
开发语言·人工智能·python
Yvonne爱编码8 小时前
JAVA数据结构 DAY6-栈和队列
java·开发语言·数据结构·python
Re.不晚8 小时前
JAVA进阶之路——无奖问答挑战1
java·开发语言
你这个代码我看不懂9 小时前
@ConditionalOnProperty不直接使用松绑定规则
java·开发语言
pas1369 小时前
41-parse的实现原理&有限状态机
开发语言·前端·javascript
琹箐9 小时前
最大堆和最小堆 实现思路
java·开发语言·算法
前端摸鱼匠9 小时前
YOLOv8 环境配置全攻略:Python、PyTorch 与 CUDA 的和谐共生
人工智能·pytorch·python·yolo·目标检测