文章目录
  1. 1. Debian/Ubuntu
    1. 1.1. 先添加源
    2. 1.2. 安装
    3. 1.3. 更新
  2. 2. Redhat/Linux
    1. 2.1. 添加源
    2. 2.2. 安装
    3. 2.3. 更新
  3. 3. ArchLinux
    1. 3.1. 安装
  4. 4. Gentoo
    1. 4.1. 配置
    2. 4.2. 安装
  5. 5. Mac OSX
    1. 5.1. 使用Homebre安装, 执行
  6. 6. 在linux中使用Linuxbrew
  7. 7. Bash,Ubuntu在Windows上
    1. 7.1. 添加源
    2. 7.2. 依赖问题
    3. 7.3. 安装
    4. 7.4. 版本更新
  8. 8. 通过tar.gz文件
  9. 9. 通过源码安装

Debian/Ubuntu

Debian分支的Linux可以使用官方的仓库来安装。

先添加源

1
curl https://dist.crystal-lang.org/apt/setup.sh | sudo bash

然后

1
2
3
apt-key adv --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54
echo "deb https://dist.crystal-lang.org/apt crystal main" > /etc/apt/sources.list.d/crystal.list
apt-get update

安装

1
sudo apt-get install crystal

更新

有新的版本发布时,使用如下命令更新

1
2
sudo apt-get update
sudo apt-get install crystal

Redhat/Linux

可以使用官方的仓库安装

添加源

1
2
3
4
5
6
7
8
curl https://dist.crystal-lang.org/rpm/setup.sh | sudo bash
rpm --import https://dist.crystal-lang.org/rpm/RPM-GPG-KEY

cat > /etc/yum.repos.d/crystal.repo <<END
[crystal]
name = Crystal
baseurl = https://dist.crystal-lang.org/rpm/
END

安装

1
sudo yum install crystal

更新

有新的版本发布时可以执行

1
sudo yum update crystal

ArchLinux

社区的仓库中已经包含了Crystal的编译器

安装

1
sudo pacman -S crystal

Gentoo

Gentoo的版本仓库已经包含了Crystal的编译器

配置

你可以先查看一下设置,运行

1
2
3
4
5
6
7
8
9
10
# equery u dev-lang/crystal
[ Legend : U - final flag setting for installation]
[ : I - package is installed with flag ]
[ Colors : set, unset ]
* Found these USE flags for dev-lang/crystal-0.18.7:
U I
- - doc : Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
- - examples : Install examples, usually source code
+ + xml : Use the dev-libs/libxml2 library to enable Crystal xml module
+ - yaml : Use the dev-libs/libyaml library to enable Crystal yaml module

安装

1
2
su -
emerge -a dev-lang/crystal

Mac OSX

使用Homebre安装, 执行

1
2
brew update
brew install crystal-lang

如果你想对Crystal捐献代码,需要同时安装LLVM, 替换上面代码的最后一行为

1
brew install crystal-lang --with-llvm

关于在 OSX 10.11 (El Capitan)的一些问题
如果报如下的错误

1
ld: library not found for -levent

你需要重装命令行工具,并选择默认的工具链

1
2
$ xcode-select --install
$ xcode-select --switch /Library/Developer/CommandLineTools

在linux中使用Linuxbrew

可以在Linux发行版中使用Linuxbrew安装Crystal

1
2
brew update
brew install crystal-lang

如果你想对Crystal捐献代码,需要同时安装LLVM, 替换上面代码的最后一行为

1
brew install crystal-lang --with-llvm

Bash,Ubuntu在Windows上

Crystal目前还不支持windows系统, 如果你使用的是Windows10 你可以尝试使用Bash on Ubuntu on Windows
(win10红石版的一个Bash环境)来安装, 安装方式跟Ubuntu的安装方式一致,但可能还是会有些问题(这是一个实验性的尝试)

添加源

1
2
3
4
5
curl -sSL https://dist.crystal-lang.org/apt/setup.sh | sudo bash

sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 09617FD37CC06B54
echo "deb https://dist.crystal-lang.org/apt crystal main" | sudo tee /etc/apt/sources.list.d/crystal.list
sudo apt-get update

依赖问题

需要安装C的编译器(cc) 和连接器(ld )

1
sudo apt-get install clang binutils

安装

1
sudo apt-get install crystal

版本更新

1
2
sudo apt-get update
sudo apt-get install crystal

通过tar.gz文件

如果你不想使用前面的任何一种安装方法, 你可以下载Crystal的单文件版本。最新版本的Github地址是 https://github.com/crystal-lang/crystal/releases
下载对应平台的版本,在包中有一个 bin/crystal的可执行文件, 创建一个符号链接到你的系统Path环境变量目录中

ln -s [full path to bin/crystal] /usr/local/bin/crystal

这样就可以直接输入 ctystal 命令来使用了。

通过源码安装

If you want to contribute then you might want to install Crystal from sources.

Install the latest Crystal release. To compile Crystal, you need Crystal :).

Make sure a supported LLVM version is present in the path. Currently, Crystal supports LLVM 3.8, 3.9 and 4.0. When possible, use the latest one. If you are using Mac and the Homebrew formula, this will be automatically configured for you if you install Crystal adding –with-llvm flag.

Make sure to install all the required libraries. You might also want to read the contributing guide.

Clone the repository:

git clone https://github.com/crystal-lang/crystal.git
Run make to build your own version of the compiler
Run make spec to ensure all specs pass, and you’ve installed everything correctly.
Use bin/crystal to run your crystal files
If you would like more information about the new bin/crystal, check out the using the compiler documentation.

Note: The actual binary is built in to .build/crystal, but the bin/crystal wrapper script is what you should use to run crystal.

文章目录
  1. 1. Debian/Ubuntu
    1. 1.1. 先添加源
    2. 1.2. 安装
    3. 1.3. 更新
  2. 2. Redhat/Linux
    1. 2.1. 添加源
    2. 2.2. 安装
    3. 2.3. 更新
  3. 3. ArchLinux
    1. 3.1. 安装
  4. 4. Gentoo
    1. 4.1. 配置
    2. 4.2. 安装
  5. 5. Mac OSX
    1. 5.1. 使用Homebre安装, 执行
  6. 6. 在linux中使用Linuxbrew
  7. 7. Bash,Ubuntu在Windows上
    1. 7.1. 添加源
    2. 7.2. 依赖问题
    3. 7.3. 安装
    4. 7.4. 版本更新
  8. 8. 通过tar.gz文件
  9. 9. 通过源码安装