xmake 是一个基于 Lua 的轻量级现代化 c /c++ 的项目构建工具,主要特点是:语法简单易上手,提供更加可读的项目维护,实现跨平台行为一致的构建体验。
本文主要详细讲解 xmake 在各个平台下的安装过程。
- 项目源码
- 官方文档
安装 Master 版本
通常情况下我们只需要通过一键安装脚本即可完成安装。
使用 curl
bash <(curl -fsSL https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh)
使用 wget
bash <(wget https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh -O -)
使用 powershell
Invoke-Expression (Invoke-Webrequest 'https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.ps1' -UseBasicParsing).Content
注:如果 ps 脚本执行提示失败,可以尝试在管理员模式下执行
安装 Windows 版本
使用安装包
windows 下提供了预制的 nsis 安装包,我们可直接从 github 的 Releases 下载页面下载后,运行安装包即可。
- 从 Releases 上下载 windows 安装包
- 运行安装程序 xmake-[version].exe
使用 scoop
scoop install xmake
MacOS
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install xmake
或者:
- 从 Releases 上下载 pkg 安装包
- 双击运行
或者安装 master 版本:
# 使用 homebrew 安装 master 版本
$ brew install xmake --HEAD
# 或者直接调用 shell 下载安装
$ bash <(curl -fsSL https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh)
Linux
在 archlinux 上安装:
$ yaourt xmake
或者下载 deb 包来安装:
- 从 Releases 上下载 deb 安装包
- 运行:
dpkg -i xmake-xxxx.deb
Termux
最新版本的 xmake 已经很好地支持了 termux,而我们也通常只需要执行上面的一键安装脚本即可,如果失败,可参考下文自己拉取源码编译安装。
源码编译安装
安装
注:切记,xmake 不建议在 root 下安装,所以尽量不要在 root 下拉取源码编译安装!
$ git clone --recursive https://github.com/xmake-io/xmake.git
$ cd ./xmake
$ ./scripts/get.sh __local__
$ source ~/.xmake/profile
如果觉得 github 的源太慢,可以通过 gitee 的镜像源拉取:clone --recursive https://gitee.com/tboox/xmake.git
注:由于目前 xmake 源码通过 git submodule 维护依赖,所以 clone 的时候需要加上 --recursive
参数同时拉取所有 submodules 代码,请不要直接下载 tar.gz 源码,因为 github 不会自动打包 submodules 里面的代码。
如果 git clone 的时候忘记加 --recursive
,那么也可以执行git submodule update --init
来拉取所有 submodules,例如:
$ git clone https://github.com/xmake-io/xmake.git
$ cd ./xmake
$ git submodule update --init
$ ./scripts/get.sh __local__
注:./get.sh __local__
是安装到 ~/.local/xmake
下,然后通过 source ~/.xmake/profile
方式来加载的,所以安装完,当前终端如果执行 xmake 失败,提示找不到,就手动执行下 source ~/.xmake/profile
,而下次打开终端就不需要了。
卸载
$ ./scripts/get.sh __uninstall__
仅仅更新安装 lua 脚本
这个开发者本地调试 xmake 源码才需要:
$ ./scripts/get.sh __local__ __install_only__
root 下安装
xmake 不推荐 root 下安装使用,因为这很不安全,如果用户非要 root 下装,装完后,如果提示 xmake 运行不了,请根据提示传递 --root
参数,或者设置 XMAKE_ROOT=y
环境变量强行启用下,前提是:用户需要随时注意 root 下误操作系统文件文件的风险。
依赖问题
- 如果遇到 readline 相关问题,请装下 readline-devel 或者 libreadline-dev 依赖,这个是可选的,仅仅
xmake lua
命令执行 REPL 时候才需要。 - 如果想要提速编译,可以装下 ccache,xmake 会自动检测并使用,这也是可选的。
其他安装方式
注:这种也是源码编译安装,但是安装路径会直接写入 /usr/
下,需要 root 权限,因此除非特殊情况,不推荐这种安装方式,建议采用上文提供的 ./get.sh __local__
方式来安装,这两种安装方式的安装路径是不同的,不要混用。
通过 make 进行编译安装:
$ make build; sudo make install
安装到其他指定目录:
$ sudo make install prefix=/usr/local
卸载:
$ sudo make uninstall
更新升级
从 v2.2.3 版本开始,新增了 xmake update
命令,来快速进行自我更新和升级,默认是升级到最新版本,当然也可以指定升级或者回退到某个版本:
$ xmake update 2.2.4
我们也可以指定更新到 master/dev 分支版本:
$ xmake update master
$ xmake update dev
从指定 git 源更新
$ xmake update github:xmake-io/xmake#master
$ xmake update gitee:tboox/xmake#dev # gitee 镜像
如果 xmake/core 没动过,仅仅更新 xmake 的 lua 脚本改动,可以加 -s/--scriptonly
快速更新 lua 脚本
$ xmake update -s dev
最后,我们如果要卸载 xmake,也是支持的:xmake update --uninstall
原文:https://tboox.org/cn/2019/11/…