Skip to content

Instantly share code, notes, and snippets.

@siegy22
Last active August 26, 2016 07:04
Show Gist options
  • Save siegy22/7af2c58b9ce1af8cb60b23ddfdab837d to your computer and use it in GitHub Desktop.
Save siegy22/7af2c58b9ce1af8cb60b23ddfdab837d to your computer and use it in GitHub Desktop.
Install redis from ruby code
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
puts "== Installing redis =="
if which("brew")
puts "Found brew 🍺"
redis = `brew ls --versions redis`
if !redis.empty?
puts("Redis is already installed. Versions:\n#{redis}")
else
system! "brew install redis"
end
else
redis = which("redis-server")
if redis
puts "Found redis in #{redis}"
else
puts "Manually installing redis..."
chdir "tmp/" do
system! "curl -O http://download.redis.io/redis-stable.tar.gz"
system! "tar -xvzf redis-stable.tar.gz"
chdir "redis-stable/" do
puts "Require sudo for make install"
system! "make && sudo make install"
puts "Redis installed! Located in: #{which "redis-server"}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment