Giter Club home page Giter Club logo

luaver's Introduction

Lua Version Manager - luaver

Build Status Join the chat at https://gitter.im/DhavalKapil/luaver License

luaver helps to manage and switch between different versions of Lua, LuaJIT and Luarocks.

Features

  1. Installs/Uninstalls any version of Lua, LuaJIT or luarocks with a single command.
  2. Switches between different versions of 'Lua', 'LuaJIT' or 'Luarocks' easily, without glitches.
  3. Consistency between 'Lua' and 'Luarocks' maintained - Rocks and configurations for different lua versions are stored differently.
  4. Every terminal session can have a different environment configured. Default versions can also be configured.

gif animation showing usage of luaver

Requirements

Requires make, either of wget or curl.

You may need to install some dependencies:

sudo apt-get install libreadline-dev 

Also, if you are planning to install older versions of Lua(which are 32-bit) on 64-bit machines, you may need to install some 32-bit libraries:

sudo apt-get install lib32ncurses5-dev

Installation

Install script

You can install from the script directly:

curl -fsSL https://raw.githubusercontent.com/dhavalkapil/luaver/master/install.sh | sh -s - -r v1.1.0

Follow the instructions which appears after the luaver installation.

Install using git

  1. Clone this repository into ~/.luaver:

    $ git clone https://github.com/DhavalKapil/luaver.git ~/.luaver
  2. Add . ~/.luaver/luaver to your profile such as .bashrc or .zshrc:

    $ echo "[ -s ~/.luaver/luaver ] && . ~/.luaver/luaver" >> ~/.bashrc
    $ echo "[ -s ~/.luaver/completions/luaver.bash ] && . ~/.luaver/completions/luaver.bash" >> ~/.bashrc
  3. Reload .bashrc or restart the shell to load luaver:

    $ . ~/.bashrc

Update using git

Note: This method only works if luaver was installed using git.

$ cd ~/.luaver && git fetch origin && git reset --hard origin/master

Additional works may be required.

Usage

Sample usage:

luaver install 5.3.1             # Installs Lua version 5.3.1
luaver install 5.3.0             # Installs Lua version 5.3.0
luaver use 5.3.1                 # Switches to Lua version 5.3.1
luaver install-luarocks 2.3.0    # Installs Luarocks version 2.3.0
luaver uninstall 5.3.0           # Uninstalls Lua version 5.3.0

Complete usage:

luaver help

Usage:
   luaver help                              Displays this message
   luaver install <version>                 Installs lua-<version>
   luaver use <version>                     Switches to lua-<version>
   luaver set-default <version>             Sets <version> as default for lua
   luaver unset-default                     Unsets the default lua version
   luaver uninstall <version>               Uninstalls lua-<version>
   luaver list                              Lists installed lua versions
   luaver install-luajit <version>          Installs luajit-<version>
   luaver use-luajit <version>              Switches to luajit-<version>
   luaver set-default-luajit <version>      Sets <version> as default for luajit
   luaver unset-default-luajit              Unsets the default luajit version
   luaver uninstall-luajit <version>        Uninstalls luajit-<version>
   luaver list-luajit                       Lists installed luajit versions
   luaver install-luarocks <version>        Installs luarocks<version>
   luaver use-luarocks <version>            Switches to luarocks-<version>
   luaver set-default-luarocks <version>    Sets <version> as default for luarocks
   luaver unset-default-luarocks            Unsets the default luarocks version
   luaver uninstall-luarocks <version>      Uninstalls luarocks-<version>
   luaver list-luarocks                     Lists all installed luarocks versions
   luaver current                           Lists present versions being used
   luaver version                           Displays luaver version

Contribution

Feel free to file issues and submit pull requests – contributions are welcome.

License

luaver is licensed under the MIT license.

luaver's People

Contributors

aajjbb avatar dhavalkapil avatar dimitriye98 avatar gitter-badger avatar piyush8311 avatar rurban avatar shagunsodhani avatar umireon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luaver's Issues

default to latest version when no <version> argument supplied

As the title says, I think this wouldn't be hard to implement and would make sure eg. that the latest bugfixes are installed.

Step 2: parse semver string and install latest compatible version

eg.: luaver install 5.3 will install the latest 5.3 series release

macosx is not detected

it falls back to linux, which is wrong.

$ uname | tr "[:upper:]" "[:lower:]"
darwin

which is != macosx

What should happen on first run?

Hi,

As things stand, if the user downloads and runs anything, including ./luavm help, luavm tries to install all its default working directories (~/.luavm etc.).

I'm not sure I think that this is the best procedure. I think it would be better to install those only when a user runs a command that requires them.

Beyond that, the installation commands have a problem. This is what the user sees when running ./luavm help

$ ./luavm help
usage: mkdir [-pv] [-m mode] directory ...
Unable to execute following command:
mkdir 
Exiting

zsh error

 echo "[ -s ~/.luaver/completions/luaver.bash ] && . ~/.luaver/completions/luaver.bash" >> ~/.zshrc
 source ~/.zshrc
~/.luaver/completions/luaver.bash:60: command not found: complete

is there something i can do about it ?

not working on MacOS

I just installed luaver. I tried to install Lua 5.3.1 and got this:

~ ❯❯❯ luaver install 5.3.1
==>  Installing lua-5.3.1
==>  Detecting already downloaded archives
==>  Downloading lua-5.3.1
==>  Downloading from http://www.lua.org/ftp/lua-5.3.1.tar.gz
--2016-08-19 15:16:02--  http://www.lua.org/ftp/lua-5.3.1.tar.gz
Resolving www.lua.org... 148.251.24.173, 2a01:4f8:201:620f::2001
Connecting to www.lua.org|148.251.24.173|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 282401 (276K) [application/gzip]
Saving to: ‘lua-5.3.1.tar.gz’

lua-5.3.1.tar.gz                    100%[==================================================================>] 275.78K  1.41MB/s    in 0.2s

2016-08-19 15:16:02 (1.41 MB/s) - ‘lua-5.3.1.tar.gz’ saved [282401/282401]

==>  Download successful
==>  Extracting archive
==>  Unpacking lua-5.3.1.tar.gz
x lua-5.3.1/
x lua-5.3.1/src/
x lua-5.3.1/src/liolib.c
x lua-5.3.1/src/lctype.h
x lua-5.3.1/src/ltm.h
x lua-5.3.1/src/ldump.c
x lua-5.3.1/src/lobject.h
x lua-5.3.1/src/lopcodes.h
x lua-5.3.1/src/luac.c
x lua-5.3.1/src/lbitlib.c
x lua-5.3.1/src/llimits.h
x lua-5.3.1/src/luaconf.h
x lua-5.3.1/src/lgc.h
x lua-5.3.1/src/lauxlib.c
x lua-5.3.1/src/lstate.h
x lua-5.3.1/src/llex.c
x lua-5.3.1/src/ldblib.c
x lua-5.3.1/src/lcode.h
x lua-5.3.1/src/lstate.c
x lua-5.3.1/src/lua.c
x lua-5.3.1/src/lzio.c
x lua-5.3.1/src/lcode.c
x lua-5.3.1/src/llex.h
x lua-5.3.1/src/lparser.c
x lua-5.3.1/src/linit.c
x lua-5.3.1/src/ldebug.h
x lua-5.3.1/src/lcorolib.c
x lua-5.3.1/src/lbaselib.c
x lua-5.3.1/src/ldebug.c
x lua-5.3.1/src/lutf8lib.c
x lua-5.3.1/src/lapi.c
x lua-5.3.1/src/lua.h
x lua-5.3.1/src/lauxlib.h
x lua-5.3.1/src/lobject.c
x lua-5.3.1/src/lstrlib.c
x lua-5.3.1/src/ltm.c
x lua-5.3.1/src/ltablib.c
x lua-5.3.1/src/lualib.h
x lua-5.3.1/src/lfunc.h
x lua-5.3.1/src/ldo.c
x lua-5.3.1/src/lfunc.c
x lua-5.3.1/src/lctype.c
x lua-5.3.1/src/lvm.c
x lua-5.3.1/src/loadlib.c
x lua-5.3.1/src/ltable.h
x lua-5.3.1/src/lstring.h
x lua-5.3.1/src/ltable.c
x lua-5.3.1/src/lua.hpp
x lua-5.3.1/src/lopcodes.c
x lua-5.3.1/src/lapi.h
x lua-5.3.1/src/lparser.h
x lua-5.3.1/src/Makefile
x lua-5.3.1/src/lundump.c
x lua-5.3.1/src/lmem.h
x lua-5.3.1/src/lundump.h
x lua-5.3.1/src/lprefix.h
x lua-5.3.1/src/lstring.c
x lua-5.3.1/src/lmathlib.c
x lua-5.3.1/src/lvm.h
x lua-5.3.1/src/lgc.c
x lua-5.3.1/src/ldo.h
x lua-5.3.1/src/lzio.h
x lua-5.3.1/src/loslib.c
x lua-5.3.1/src/lmem.c
x lua-5.3.1/README
x lua-5.3.1/doc/
x lua-5.3.1/doc/luac.1
x lua-5.3.1/doc/osi-certified-72x60.png
x lua-5.3.1/doc/manual.css
x lua-5.3.1/doc/readme.html
x lua-5.3.1/doc/logo.gif
x lua-5.3.1/doc/index.css
x lua-5.3.1/doc/contents.html
x lua-5.3.1/doc/manual.html
x lua-5.3.1/doc/lua.1
x lua-5.3.1/doc/lua.css
x lua-5.3.1/Makefile
==>  Unpack successful
remove lua-5.3.1.tar.gz? y
__luaver_get_platform:3: number expected

If I try to use Lua:

~/.l/src ❯❯❯ luaver use 5.3.1
==>  Switching to lua-5.3.1
__luaver_use_lua:read:12: -p: no coprocess
Unable to use lua-5.3.1

If I try to uninstall it:

~/.l/src ❯❯❯ luaver uninstall 5.3.1                                                                                                          ⏎
==>  Uninstalling lua-5.3.1
lua-5.3.1 is not installed

I'm on 10.10.5 using zsh 5.2

Any idea on what I'm doing wrong?

install.sh installs old version that is incompatible with macosx

might be related to #12, #11

Both running install.sh and installing luaver with homebrew installs an old version of luaver. This basically makes the function __luaver_get_platform() outdated. In MacOSX systems this means that luaver thinks it's running on linux, and compilation obviously fails.

Fatal error: string.h: No such file or directory

When I try luaver install 5.3.4 I get

==>  Detecting already downloaded archives
lua-5.3.4 has already been downloaded. Download again? [Y/n]: y
rm: remove write-protected regular file 'lua-5.3.4/doc/lua.1'? y
==>  Downloading lua-5.3.4
==>  Downloading from http://www.lua.org/ftp/lua-5.3.4.tar.gz
--2017-05-21 17:44:06--  http://www.lua.org/ftp/lua-5.3.4.tar.gz
Resolving www.lua.org (www.lua.org)... 148.251.24.173, 2a01:4f8:201:620f::2001
Connecting to www.lua.org (www.lua.org)|148.251.24.173|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 303586 (296K) [application/gzip]
Saving to: ‘lua-5.3.4.tar.gz’

lua-5.3.4.tar.gz                                100%[=====================================================================================================>] 296.47K   230KB/s    in 1.3s    

2017-05-21 17:44:08 (230 KB/s) - ‘lua-5.3.4.tar.gz’ saved [303586/303586]

==>  Download successful
==>  Extracting archive
==>  Unpacking lua-5.3.4.tar.gz
lua-5.3.4/
lua-5.3.4/Makefile
lua-5.3.4/doc/
lua-5.3.4/doc/luac.1
lua-5.3.4/doc/manual.html
lua-5.3.4/doc/manual.css
...
lua-5.3.4/src/lapi.c
lua-5.3.4/src/lparser.h
lua-5.3.4/src/lua.hpp
lua-5.3.4/src/lstrlib.c
lua-5.3.4/README
==>  Unpack successful
==>  Detecting platform
==>  Platform detected: linux
==>  Compiling lua-5.3.4
cd src && make linux
make[1]: Entering directory '/home/sam/.luaver/src/lua-5.3.4/src'
make all SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
make[2]: Entering directory '/home/sam/.luaver/src/lua-5.3.4/src'
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX    -c -o lapi.o lapi.c
lapi.c:14:20: fatal error: string.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'lapi.o' failed
make[2]: *** [lapi.o] Error 1
make[2]: Leaving directory '/home/sam/.luaver/src/lua-5.3.4/src'

Any idea of whats wrong?

no luarocks in

Whenever I start a new terminal session it writes
/usr/bin/which: no luarocks in (/home/jonathan/.luaver/lua/5.1.5/bin:/home/jonathan/.nvm/versions/node/v6.4.0/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/jonathan/.local/bin:/home/jonathan/bin) at the top. My guess is that it can't find luarocks in path.

Trouble using `luaver use-luajit`

I successfully ran luaver install-luajit 2.1.0-beta2 and it built LuaJIT. However, it did not show up after building Lua 5.1:

hisham@pointer ~/junkcode/noise]luaver current
==>  Current versions:
==>  lua-5.1.5
==>  luarocks-2.4.1

I tried to run luaver use-luajit and got a weird (buggy?) result:

hisham@pointer ~/junkcode/noise]luaver use-luajit 
==>  Switching to LuaJIT-
==>  Successfully switched to LuaJIT-

Apparently, this did nothing, fortunately.

hisham@pointer ~/junkcode/noise]luaver current
==>  Current versions:
==>  lua-5.1.5
==>  luarocks-2.4.1

So I tried it with an argument...

hisham@pointer ~/junkcode/noise]luaver use-luajit 2.10-beta2
==>  Switching to LuaJIT-2.10-beta2
LuaJIT-2.10-beta2 is not installed. Want to install it? [Y/n]: y
==>  Installing lua-2.10-beta2
==>  Detecting already downloaded archives
==>  Downloading lua-2.10-beta2
==>  Downloading from http://www.lua.org/ftp/lua-2.10-beta2.tar.gz
--2017-03-01 18:55:46--  http://www.lua.org/ftp/lua-2.10-beta2.tar.gz
Resolving www.lua.org (www.lua.org)... 148.251.24.173, 2a01:4f8:201:620f::2001
Connecting to www.lua.org (www.lua.org)|148.251.24.173|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-03-01 18:55:47 ERROR 404: Not Found.

Unable to execute the following command:
wget http://www.lua.org/ftp/lua-2.10-beta2.tar.gz
Exiting

...but that produced a really confused result.

Named virtual environment

It would be quite nice to be able to create named virtualenvironments with luaver, just like in python. Sometimes, one has multiple projects with multiple incompatible dependencies for the same lua version.

Feature request: cd back to original directory

It would be nicer if the install.sh script ran cd back to the original directory where I was originally, instead of leaving the shell at ~/.luaver. Perhaps it could also print in the end something like


Installation successful!
You can now run 'luaver' to see available commands.

#include <readline/readline.h>

Hi

I have a problem when I try change my lua version. All the time I recive this mesage:

alexandre@alexandre-Aspire-E1-571:~$ luaver install 5.1
==> Installing lua-5.1
==> Detecting already downloaded archives
==> lua-5.1 has already been downloaded. Download again? [Y/n]:
n
==> Detecting platform
==> Platform detected: linux
==> Compiling lua-5.1
cd src && make linux
make[1]: Entering directory '/home/alexandre/.luaver/src/lua-5.1/src'
make all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
make[2]: Entering directory '/home/alexandre/.luaver/src/lua-5.1/src'
gcc -O2 -Wall -DLUA_USE_LINUX -c -o lua.o lua.c
In file included from lua.h:16:0,
from lua.c:15:
luaconf.h:263:10: fatal error: readline/readline.h: No such file or directory
#include <readline/readline.h>
^~~~~~~~~~~~~~~~~~~~~

compilation terminated.
: recipe for target 'lua.o' failed
make[2]: *** [lua.o] Error 1
make[2]: Leaving directory '/home/alexandre/.luaver/src/lua-5.1/src'
Makefile:95: recipe for target 'linux' failed
make[1]: *** [linux] Error 2
make[1]: Leaving directory '/home/alexandre/.luaver/src/lua-5.1/src'
Makefile:54: recipe for target 'linux' failed
make: *** [linux] Error 2
Unable to execute the following command:
make
Exiting

My so version is Ubuntu 18.04.2 LTS
and I installed the package libreadline-dev

Can help me?
Tu

Better fish support

I have created a better fish support that is I converted the luaver script file to luaver fish script file.

I would like to contribute it to this project if possible.

Request: also add current Lua version to pkg-config

I have Lua 5.3 installed both as an Ubuntu package and through luaver. However, pkg-config points to the system Lua even when I am using luaver:

$ luaver use 5.3.5
==>  Switching to lua-5.3.5
==>  Successfully switched to lua-5.3.5

$ pkg-config --cflags --libs lua5.3
-I/usr/include/lua5.3 -llua5.3

Would you be open to creating a .pc file and adding it to PKG_CONFIG_PATH on luaver use? That way autoconf or other pkg-config users would find my luaver lua rather than the system lua. Thanks for considering this request!

(tested on Lubuntu Eoan)

"Rockset" feature

Would it be possible to have a "rockset" feature like rvm's gemsets?

The idea is to allow the definition of not only different Lua versions, but also per-project Lua environments. So, if I had a project "foo" and a project "bar", both using Lua 5.3 but different rock sets, I could switch between their environments with the commands

$ luaver use [email protected]
$ luaver use [email protected]

The main benefit is that you get a finer control over the versions of the rocks you use, specially when there are incompatibilities. I never ran into this kind of situation though, so this feature might just be overkill. It does give me peace of mind to know that my projects have only the strictly required rocks installed in their environment.

Luaver kill the whole batch process on error

The following script will not work as expected:

. ~/.luaver/luaver
if luaver install-luarocks install 5.3.1; then
    echo ok
else
    echo Something wrong
fi

The result was:

$ sh test.sh
No lua version set

$

while printing Something wrong is the expected behavior.

This is caused by luaver#L34, which kills not only the luaver function but also the whole batch process.
This behavior makes difficult to use luaver on the CI.

Since there is no exception handling mechanism on shells (kill -INT $$ is appearently not working), I suggest each command has explicit error handling using && and if.

Problems installing with zsh

Tried installing it with the curl line from README.md, and got this error:

==>  Detected SHELL_TYPE: zsh
set_up_path:7: = not found

After that, I'm in the ~/.luaver directory, but typing the luaver command does nothing.

I launched bash, reran the curl installation line, and things worked as expected.

Open to installing various other versions of luajit?

Hello,

I'd like to use luaver to install versions of luajit more recent than 2.1.0-beta3 or forks of luajit, because 2.1.0-beta3 segfaults on lots of well-behaved lua programs like this one https://gist.github.com/sharpobject/1a119447c15a3daa3933531f320a269d

Would you be open to a PR that adds the option to install more recent versions of luajit from https://github.com/LuaJIT/LuaJIT or forks of luajit from https://github.com/openresty/luajit2 or https://github.com/moonjit/moonjit?

If so, do you have any thoughts on how that should work? With the exception of moonjit, I don't think we will get tagged releases from these repositories.

Problem with install.sh

Problem 1
In install.sh (line 32), I set LUAVER_DIR to a different dir which was not the default ~/.luaver
The profiles which were set in ~/.bashrc used ~/.luaver
They should have used the folder I set in the variable LUAVER_DIR

TDLR:
Wrong profiles for custom folder

Problem 2
In the luaver file (line 14), __luaver_LUAVER_DIR should automatically be set to the new luaver dir I set in install.sh

TDLR:
The install.sh script should pass on LUAVER_DIR from install.sh to __luaver_LUAVER_DIR in luaver

Note:
Please explicitly comment above line 14 in the luaver file that ~ cannot be use, instead ${HOME} should be used e.g. Cannot be '~/dir/dir', should be ${HOME}/dir/dir

Suggestion: dash compatibility

dash is the default implementation of /bin/sh in Debian and Ubuntu and is a POSIX-compliant shell.

Making luaver dash-compatible will elegantly solve every portability issue such as on zsh and on macOS.

I think this is easy for luaver because luaver does not heavily use bash-specific features.

small typo

Nice software. A tiny correction: I think when a module is successfully installed the message like

lua-5.3.2 successfully installed. Do you want to this version? [Y/n]: Y

are probably meant to read

lua-5.3.2 successfully installed. Do you want switch to this version? [Y/n]: Y

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.