欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 名人名企 > 使用reflex的序章:安装cargo、fnm和bun

使用reflex的序章:安装cargo、fnm和bun

2025/2/24 15:04:18 来源:https://blog.csdn.net/skywalk8163/article/details/141791764  浏览:    关键词:使用reflex的序章:安装cargo、fnm和bun

安装好reflex后,需要安装好cargo和fnm

安装cargo

apt install cargo

设置加速镜像

在.cargo/config文件里写入:

[source.crates-io]
replace-with = 'mirror'[source.mirror]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

安装margo的新版本

sudo npm install major

 

安装fnm

cargo install fnm

设置npm的加速镜像

npm config set registry https://registry.npm.taobao.org/

使用镜像源可以加快npm包的下载和安装速度,尤其是在国内网络环境下。你可以通过设置npm的配置来切换镜像源。例如,要使用淘宝源,可以执行以下命令:

npm config set registry https://registry.npm.taobao.org/

或者要使用cnpm源,可以执行以下命令:

npm config set registry http://r.cnpmjs.org/

切换镜像源后,再使用npm安装包时,npm将会从对应的镜像源下载和安装包。

npm update 

有些慢,感觉卡住了

发现Node版本不一致,报错信息里显示要用18.17,手工下载安装

# installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash# activate fnm
source ~/.bashrc# download and install Node.js
fnm use --install-if-missing 18# verifies the right Node.js version is in the environment
node -v # should print `v18.20.4`# verifies the right npm version is in the environment
npm -v # should print `10.7.0`

reflex需要的是18.17 ,这个下载不下来。手工下载install文件,执行后github下载fnm失败。

升级nodejs

sudo apt upgrade nodejs

npm 设置镜像

(base) skywalk@ub:~/app1$ npm config set registry https://registry.npmmirror.com
(base) skywalk@ub:~/app1$ npm config get registry
https://registry.npmmirror.com
(base) skywalk@ub:~/app1$ npm updateup to date in 11s23 packages are looking for fundingrun `npm fund` for details

安装rustup

安装rustup

sudo snap install rustup --classic

 然后升级到nightly版本

rustup install nightly
rustup default nightly

升级后还是无法安装bun

手工安装bun

curl -fsSL https://bun.sh/install | bash

 手工安装bun 失败,主要是github有问题。

尝试手工npm 安装bun

sudo npm install -g bun 

安装成了。

 结论:

因为特殊的国情,涉及到github自动下载安装的部分存在很大的坑,导致cargo 安装bun会失败,进而导致reflex init会失败。

解决的方法:

cargo升级到最新,npm最新,rustup 设为nightly

rustup install nightly
rustup default nightly

若cargo安装bun失败,curl安装bun失败,可以尝试使用npm安装bun 。

sudo npm install -g bun 

调试

报错error: Can't download the requested binary: error sending request

for url

⠦ Installing node Installing Node v18.17.0 (x64)

Installing node failed with exit code 1

Installing Node v18.17.0 (x64)

error: Can't download the requested binary: error sending request

for url

(https://nodejs.org/dist/v18.17.0/node-v18.17.0-linux-x64.tar.xz):

operation timed out

Run with --loglevel debug  for the full log.

初始化的时候报错。。。

初始化报错

reflex init

──────────────────────── Initializing work ────────────────────────

Installing node failed with exit code 1

Installing Node v18.17.0 (x64)

error: Can't download the requested binary: error sending request

for url

(https://nodejs.org/dist/v18.17.0/node-v18.17.0-linux-x64.tar.xz):

operation timed out

Run with --loglevel debug  for the full log.

报错error: Failed to download bun from

error: Failed to download bun from

"https://github.com/oven-sh/bun/releases/download/bun-v1.1.10/bun-l

inux-x64-baseline.zip"

Run with --loglevel debug  for the full log.

手工下载bun

npm install bun

报错变成

报错:Installing https://bun.sh/install failed with exit code 1

#!/usr/bin/env bash
set -euo pipefailplatform=$(uname -ms)if [[ ${OS:-} = Windows_NT ]]; thenif [[ $platform != MINGW64* ]]; thenpowershell -c "irm bun.sh/install.ps1|iex"exit $?fi
fi# Reset
Color_Off=''# Regular Colors
Red=''
Green=''
Dim='' # White# Bold
Bold_White=''
Bold_Green=''if [[ -t 1 ]]; then# ResetColor_Off='\033[0m' # Text Reset# Regular ColorsRed='\033[0;31m'   # RedGreen='\033[0;32m' # GreenDim='\033[0;2m'    # White# BoldBold_Green='\033[1;32m' # Bold GreenBold_White='\033[1m'    # Bold White
fierror() {echo -e "${Red}error${Color_Off}:" "$@" >&2exit 1
}info() {echo -e "${Dim}$@ ${Color_Off}"
}info_bold() {echo -e "${Bold_White}$@ ${Color_Off}"
}success() {echo -e "${Green}$@ ${Color_Off}"
}command -v unzip >/dev/null ||error 'unzip is required to install bun'if [[ $# -gt 2 ]]; thenerror 'Too many arguments, only 2 are allowed. The first can be a specific tag of bun to install. (e.g. "bun-v0.1.4") The second can be a build variant of bun to install. (e.g. "debug-info")'
ficase $platform in
'Darwin x86_64')target=darwin-x64;;
'Darwin arm64')target=darwin-aarch64;;
'Linux aarch64' | 'Linux arm64')target=linux-aarch64;;
'MINGW64'*)target=windows-x64;;
'Linux x86_64' | *)target=linux-x64;;
esacif [[ $target = darwin-x64 ]]; then# Is this process running in Rosetta?# redirect stderr to devnull to avoid error message when not running in Rosettaif [[ $(sysctl -n sysctl.proc_translated 2>/dev/null) = 1 ]]; thentarget=darwin-aarch64info "Your shell is running in Rosetta 2. Downloading bun for $target instead"fi
fiGITHUB=${GITHUB-"https://github.com"}github_repo="$GITHUB/oven-sh/bun"if [[ $target = darwin-x64 ]]; then# If AVX2 isn't supported, use the -baseline buildif [[ $(sysctl -a | grep machdep.cpu | grep AVX2) == '' ]]; thentarget=darwin-x64-baselinefi
fiif [[ $target = linux-x64 ]]; then# If AVX2 isn't supported, use the -baseline buildif [[ $(cat /proc/cpuinfo | grep avx2) = '' ]]; thentarget=linux-x64-baselinefi
fiexe_name=bunif [[ $# = 2 && $2 = debug-info ]]; thentarget=$target-profileexe_name=bun-profileinfo "You requested a debug build of bun. More information will be shown if a crash occurs."
fiif [[ $# = 0 ]]; thenbun_uri=$github_repo/releases/latest/download/bun-$target.zip
elsebun_uri=$github_repo/releases/download/$1/bun-$target.zip
fiinstall_env=BUN_INSTALL
bin_env=\$$install_env/bininstall_dir=${!install_env:-$HOME/.bun}
bin_dir=$install_dir/bin
exe=$bin_dir/bunif [[ ! -d $bin_dir ]]; thenmkdir -p "$bin_dir" ||error "Failed to create install directory \"$bin_dir\""
ficurl --fail --location --progress-bar --output "$exe.zip" "$bun_uri" ||error "Failed to download bun from \"$bun_uri\""unzip -oqd "$bin_dir" "$exe.zip" ||error 'Failed to extract bun'mv "$bin_dir/bun-$target/$exe_name" "$exe" ||error 'Failed to move extracted bun to destination'chmod +x "$exe" ||error 'Failed to set permissions on bun executable'rm -r "$bin_dir/bun-$target" "$exe.zip"tildify() {if [[ $1 = $HOME/* ]]; thenlocal replacement=\~/echo "${1/$HOME\//$replacement}"elseecho "$1"fi
}success "bun was installed successfully to $Bold_Green$(tildify "$exe")"if command -v bun >/dev/null; then# Install completions, but we don't care if it failsIS_BUN_AUTO_UPDATE=true $exe completions &>/dev/null || :echo "Run 'bun --help' to get started"exit
firefresh_command=''tilde_bin_dir=$(tildify "$bin_dir")
quoted_install_dir=\"${install_dir//\"/\\\"}\"if [[ $quoted_install_dir = \"$HOME/* ]]; thenquoted_install_dir=${quoted_install_dir/$HOME\//\$HOME/}
fiechocase $(basename "$SHELL") in
fish)# Install completions, but we don't care if it failsIS_BUN_AUTO_UPDATE=true SHELL=fish $exe completions &>/dev/null || :commands=("set --export $install_env $quoted_install_dir""set --export PATH $bin_env \$PATH")fish_config=$HOME/.config/fish/config.fishtilde_fish_config=$(tildify "$fish_config")if [[ -w $fish_config ]]; then{echo -e '\n# bun'for command in "${commands[@]}"; doecho "$command"done} >>"$fish_config"info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_fish_config\""refresh_command="source $tilde_fish_config"elseecho "Manually add the directory to $tilde_fish_config (or similar):"for command in "${commands[@]}"; doinfo_bold "  $command"donefi;;
zsh)# Install completions, but we don't care if it failsIS_BUN_AUTO_UPDATE=true SHELL=zsh $exe completions &>/dev/null || :commands=("export $install_env=$quoted_install_dir""export PATH=\"$bin_env:\$PATH\"")zsh_config=$HOME/.zshrctilde_zsh_config=$(tildify "$zsh_config")if [[ -w $zsh_config ]]; then{echo -e '\n# bun'for command in "${commands[@]}"; doecho "$command"done} >>"$zsh_config"info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_zsh_config\""refresh_command="exec $SHELL"elseecho "Manually add the directory to $tilde_zsh_config (or similar):"for command in "${commands[@]}"; doinfo_bold "  $command"donefi;;
bash)# Install completions, but we don't care if it failsIS_BUN_AUTO_UPDATE=true SHELL=bash $exe completions &>/dev/null || :commands=("export $install_env=$quoted_install_dir""export PATH=$bin_env:\$PATH")bash_configs=("$HOME/.bashrc""$HOME/.bash_profile")if [[ ${XDG_CONFIG_HOME:-} ]]; thenbash_configs+=("$XDG_CONFIG_HOME/.bash_profile""$XDG_CONFIG_HOME/.bashrc""$XDG_CONFIG_HOME/bash_profile""$XDG_CONFIG_HOME/bashrc")fiset_manually=truefor bash_config in "${bash_configs[@]}"; dotilde_bash_config=$(tildify "$bash_config")if [[ -w $bash_config ]]; then{echo -e '\n# bun'for command in "${commands[@]}"; doecho "$command"done} >>"$bash_config"info "Added \"$tilde_bin_dir\" to \$PATH in \"$tilde_bash_config\""refresh_command="source $bash_config"set_manually=falsebreakfidoneif [[ $set_manually = true ]]; thenecho "Manually add the directory to $tilde_bash_config (or similar):"for command in "${commands[@]}"; doinfo_bold "  $command"donefi;;
*)echo 'Manually add the directory to ~/.bashrc (or similar):'info_bold "  export $install_env=$quoted_install_dir"info_bold "  export PATH=\"$bin_env:\$PATH\"";;
esacecho
info "To get started, run:"
echoif [[ $refresh_command ]]; theninfo_bold "  $refresh_command"
fiinfo_bold "  bun --help"

手工安装nodejs 18版本报错

sh nodeinstall

nodeinstall: 24: [[: not found

Checking dependencies for the installation script...

Checking availability of curl... OK!

Checking availability of unzip... OK!

Downloading https://github.com/Schniz/fnm/releases/latest/download/fnm-linux.zip...

curl: (56) OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0

Download failed.  Check that the release/filename are correct.

应该是版本低了

还会用cargo install fnm试试

init时报错error: Failed to download bun from

59.5%curl: (92) HTTP/2 stream 0 was not closed cleanly:

PROTOCOL_ERROR (err 1)

error: Failed to download bun from

"https://github.com/oven-sh/bun/releases/download/bun-v1.1.10/bun-l

inux-x64-baseline.zip"

 使用cargo install bun试试

安装bun报错error: failed to compile `bun v0.1.0`,

warning: build failed, waiting for other jobs to finish...

error: failed to compile `bun v0.1.0`, intermediate artifacts can be found at `/tmp/cargo-installCMSJBe`.

To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

Error: Pear requires a 'dev' or 'nightly' version of rustc.

        安装rustc rustc-1.76 试试

不行,

安装rust-all试试

sudo apt install rust-all

然后安装rustup

sudo snap install rustup --classic

然后升级到nightly版本

rustup install nightly

然后再来安装bun

还是一样的报错

手工安装bun

curl -fsSL https://bun.sh/install | bash

安装失败,主要是github有问题。

手工npm 安装bun

sudo npm install -g bun 

安装margo的新版本

sudo npm install major

安装之后,再安装bun,还是一样失败。

实在搞不定,放弃。

后来一通整,bun这边竟然过去了。也就是执行reflex init 通过了!

reflex init[06:11:11] Initializing the web directory.           console.py:104Get started with a template:
(0) blank (https://blank-template.reflex.run) - A minimal template
(1) dashboard (https://dashboard-new.reflex.run/) - A dashboard 
with tables and graphs
(2) sales (https://sales-new.reflex.run/) - An app to manage sales 
and customers
(3) ai_image_gen (https://ai-image-gen.reflex.run/) - An app to 
generate images using AI
(4) ci_template (https://cijob.reflex.run/) - A template for 
continuous integration
(5) api_admin_panel (https://api-admin-panel.reflex.run/) - An 
admin panel for an api.
(6) nba (https://nba-new.reflex.run/) - A data visualization app 
for NBA data.
(7) customer_data_app (https://customer-data-app.reflex.run/) - An 
app to manage customer data.
Which template would you like to use? (0): [06:11:24] Initializing the app directory.           console.py:104
Success: Initialized app1

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词