Skip to content

Instantly share code, notes, and snippets.

@sitkevij
Last active April 18, 2024 06:20
Show Gist options
  • Save sitkevij/9b507f0b987dcbdc5ffcae4d5dea2805 to your computer and use it in GitHub Desktop.
Save sitkevij/9b507f0b987dcbdc5ffcae4d5dea2805 to your computer and use it in GitHub Desktop.

Torch can be installed to your home folder in ~/torch by running these three commands:

in a terminal, run the commands WITHOUT sudo

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; bash install-deps;
./install.sh

The first script installs the basic package dependencies that LuaJIT and Torch require. The second script installs LuaJIT, LuaRocks, and then uses LuaRocks (the lua package manager) to install core packages like torch, nn and paths, as well as a few other packages.

The script adds torch to your PATH variable. You just have to source it once to refresh your env variables. The installation script will detect what is your current shell and modify the path in the correct configuration file.

On Linux with bash

source ~/.bashrc

On Linux with zsh

source ~/.zshrc

On OSX or in Linux with none of the above.

source ~/.profile

If you ever need to uninstall torch, simply run the command:

rm -rf ~/torch

If you want to install torch with Lua 5.2 instead of LuaJIT, simply run:

git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch

clean old torch installation

./clean.sh

optional clean command (for older torch versions)

curl -s https://raw.githubusercontent.com/torch/ezinstall/master/clean-old.sh | bash

https://github.com/torch/distro : set env to use lua

TORCH_LUA_VERSION=LUA52 ./install.sh

New packages can be installed using Luarocks from the command-line:

run luarocks WITHOUT sudo

$ luarocks install image
$ luarocks list

Once installed you can run torch with the command th from you prompt!

The easiest way to learn and experiment with Torch is by starting an interactive session (also known as the torch read-eval-print loop or TREPL):

$ th

Alternative install

luarocks --from=https://raw.githubusercontent.com/torch/rocks/master/ install nngraph

Torch Cheatsheet

https://github.com/torch/torch7/wiki/Cheatsheet

Ubuntu PCRE install (required by some Torch projects)

sudo apt-get install libpcre3 libpcre3-dev

add Torch directory to PATH

vim ~/.bashrc
export PATH="$HOME/torch/install/bin:$PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment