Ubuntu 安装 lua

获取 lua 源码

可以到官网获取最新一份

curl -R -O http://www.lua.org/ftp/lua-5.3.3.tar.gz
tar zxf lua-5.3.3.tar.gz

编译安装

cd lua-5.3.3
make linux test

遇到的报错

gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX    -c -o lua.o lua.c
lua.c:80:10: fatal error: readline/readline.h: No such file or directory
   80 | #include <readline/readline.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.

依据提示可以看出是缺少 libreadline-dev,安装依赖

apt-get install libreadline-dev

再次编译安装

# make linux test
# make linux install
cd src && make linux
make[1]: Entering directory ‘/home/melt/software/lua-5.3.3/src‘
make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
make[2]: Entering directory ‘/home/melt/software/lua-5.3.3/src‘
make[2]: Nothing to be done for ‘all‘.
make[2]: Leaving directory ‘/home/melt/software/lua-5.3.3/src‘
make[1]: Leaving directory ‘/home/melt/software/lua-5.3.3/src‘
cd src && mkdir -p /usr/local/bin /usr/local/include /usr/local/lib /usr/local/man/man1 /usr/local/share/lua/5.3 /usr/local/lib/lua/5.3
cd src && install -p -m 0755 lua luac /usr/local/bin
cd src && install -p -m 0644 lua.h luaconf.h lualib.h lauxlib.h lua.hpp /usr/local/include
cd src && install -p -m 0644 liblua.a /usr/local/lib
cd doc && install -p -m 0644 lua.1 luac.1 /usr/local/man/man1

可以看到相关的执行文件已经被拷贝到 /usr/local/bin,头文件被拷贝到 /usr/local/include,静态库拷贝到 /usr/local/lib,man 文档拷贝到 /usr/local/man/man1

测试

lua 版本输出成功,环境搭建完成。

# lua -v
Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio

Ubuntu 安装 lua

上一篇:js方法类库封装的简易示例


下一篇:设置vim编辑器中的tab键对应的空格数