crystal-chinaChina
  • 本站源码
  • 注册
  • 登录
目录
  • 前言
  • 简介
  • 安装 ➤
    • 包管理
  • 写给 Rubyists ➤
    • 类型
    • 方法
    • 代码块
    • 杂项
    • 性能因素
    • 迁移 Ruby 代码到 Crystal
  • 基础知识
  • 交叉编译

安装

创建于:2025年03月16日 最后编辑于: 2025年06月16日 | 125次阅读

详细安装教程,请查看 官方文档

这里仅介绍常见的几个系统安装方式:

§ Linux

§ Debian & RPM

   1  
   2  curl -fsSL https://crystal-lang.org/install.sh | sudo bash
   3  

§ Debian/Ubuntu

   1  
   2  sudo apt install crystal ${hello}
   3  

§ Alpine Linux

   1  
   2  apk add crystal shards ${hello}
   3  

§ Arch linux

   1  
   2  sudo pacman -S crystal
   3  

§ 编译安装

作为 Crystal 语言开发者,编译安装 Crystal 是首选的, 而且可以开启实现性的解释器支持。

以在 Arch Linux 编译当前最新的 Crystal 1.15.1 为例,假设我们希望编译并安装 Crystal 到 ~/Crystal 文件夹,你需要将 ~/Crystal/bin 加入 $PATH 靠前的位置来直接使用 crystal 命令

§ 安装编译及安装所需依赖

   1  
   2  sudo pacman -S base-devel \
   3         automake \
   4         git rsync \
   5         gmp \
   6         pcre2 \
   7         openssl \
   8         libtool \
   9         libyaml \
  10         llvm lld \
  11         wasmer wasmtime \
  12      ;
  13  

§ 使用 git clone 官方 github repo

   1  
   2  git clone https://github.com/crystal-lang/crystal.git && cd crystal
   3  git checkout 1.15.1
   4  

§ 编译 Crystal

   1  
   2  make clean
   3  install_target=~/Crystal
   4  mkdir -p output $install_target/bin $install_target/share $install_target/share/crystal/src/llvm/ext/
   5  FLAGS="-Dpreview_mt" make crystal interpreter=1 stats=1 release=1
   6  

§ 安装 Crystal

   1  
   2  rm -rf tmp
   3  DESTDIR=$PWD/tmp make install
   4  cp -v tmp/usr/local/bin/crystal $install_target/bin/
   5  rsync -ahP --delete tmp/usr/local/share/ $install_target/share/
   6  

然后将 ~/Crystal/bin 加入 $PATH 即可。

§ 生成并安装静态文档

   1  
   2  rm -rf docs && make docs
   3  rsync -ahP --delete docs/ $install_target/docs
   4  

这样,你可以直接用浏览器浏览本地的文档 ~/Crystal/docs/index.html

§ 安装包管理工具 shards

见 package_manager


§ macOS

§ Homebrew

   1  
   2  brew install crystal
   3  

§ MacPorts

   1  
   2  port install crystal
   3  

§ tarball


§ asdf (For linux/macos)

   1  
   2  asdf plugin add crystal
   3  asdf install crystal latest
   4  

§ Windows

§ scoop

在一个非超级用户的 PowerShell 终端运行如下命令安装 scoop 到 C:\Users<YOUR USERNAME>\scoop

   1  
   2  Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
   3  Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
   4  

运行如下命令安装 Crystal

   1  
   2  scoop install git
   3  scoop bucket add crystal-preview https://github.com/neatorobito/scoop-crystal
   4  scoop install vs_2022_cpp_build_tools crystal
   5  

§ Docker

   1  
   2  docker pull crystallang/crystal
   3  
previous_page简介

安装

next_page包管理
欢迎在评论区留下你的见解、问题或建议
登录后添加评论

正在预览...
正在读取评论...
Crystal Chinaadmin@crystal-china.org在线用户 0 人, 游客 0 人
githubx.comcrystal-lang