mac 安裝 redis


至關於 Ubuntu/Linux 的 apt-get,用來安裝一些零零碎碎的東西很方便,並且更新很快,安裝的軟件也都是最新版本。

1. 安裝

Homebrew 是使用 ruby 寫的,採用 github 來存放信息庫,很方便吧。

Ruby 已經內置,最好裝上 Xcode,由於可能須要一些編譯包。而後在終端執行如下命令。
$ ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"
brew 安裝的軟件存放在 /usr/local/Cellar 中,同時會在 /usr/local/bin, /usr/local/sbin, /usr/local/lib 中建立連接。你可能須要將 /usr/local/sbin 添加到搜索路徑中。
$ vim ~/.profile

PATH="$PATH:/usr/local/sbin"
export PATH
2. 使用

(1) 更新庫信息
$ brew update

remote: Counting objects: 116, done.
remote: Compressing objects: 100% (95/95), done.
remote: Total 95 (delta 73), reused 0 (delta 0)
Unpacking objects: 100% (95/95), done.
From http://github.com/mxcl/homebrew
* branch master -> FETCH_HEAD
Updated Homebrew from 780c85bd to d7ff3a29.
==> The following formulae are new:
dfu-programmer grass
==> The following formulae were updated:
bash-completion fiwalk git-flow hub mkclean xapian
cherokee flac groovy id3lib mkvalidator
ctags git guile kyoto-cabinet poco
No external commands were updated.
(2) 搜索軟件
$ brew search redis

redis redis-tools

$ brew search jpg # 局部搜索

libjpg

$ brew search /^libjp[e]?g/ # 正則表達式搜索

libjpeg libjpg
(3) 查看軟件信息
$ brew info redis

redis 2.0.4
http://redis.io/
/usr/local/Cellar/redis/2.0.4 (147 files, 1.2M)

If this is your first install, automatically load on login with:
cp /usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

If this is an upgrade and you already have the io.redis.redis-server.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/io.redis.redis-server.plist
cp /usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

To start redis manually:
redis-server /usr/local/etc/redis.conf

To access the server:
redis-cli

http://github.com/mxcl/homebrew/commits/master/Library/Formula/redis.rb
(4) 瀏覽軟件主頁
$ brew home redis
(5) 安裝軟件
$ brew install redis

==> Downloading https://github.com/antirez/redis/tarball/v2.0.4-stable
######################################################################## 100.0%
==> make -C .
==> Caveats
If this is your first install, automatically load on login with:
cp /usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

If this is an upgrade and you already have the io.redis.redis-server.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/io.redis.redis-server.plist
cp /usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

To start redis manually:
redis-server /usr/local/etc/redis.conf

To access the server:
redis-cli
==> Summary
/usr/local/Cellar/redis/2.0.4: 147 files, 1.2M, built in 6 seconds
(6) 刪除軟件
$ brew uninstall redis

Uninstalling /usr/local/Cellar/redis/2.0.4...
(7) 查看已經安裝的軟件
$ brew list

binutils gettext libevent nginx pstree readline valgrind
erlang glib libiconv pcre python3 redis wget
gdbm libev mongodb pkg-config rabbitmq sqlite
(8) 查看某軟件的安裝文件
$ brew list redis

/usr/local/Cellar/redis/2.0.4/bin/redis-server
/usr/local/Cellar/redis/2.0.4/bin/redis-cli
/usr/local/Cellar/redis/2.0.4/bin/redis-check-dump
/usr/local/Cellar/redis/2.0.4/bin/redis-check-aof
/usr/local/Cellar/redis/2.0.4/bin/redis-benchmark
/usr/local/Cellar/redis/2.0.4/io.redis.redis-server.plist
/usr/local/Cellar/redis/2.0.4/share/doc/ (138 files)
(9) 查看某軟件的 brew 安裝腳本
$ brew cat redis

require 'formula'

class Redis <Formula
url '
head 'git://github.com/antirez/redis.git'
homepage '
sha1 '48300996d3d34cccf076330859f37248fa5f6c1b'
version '2.0.4'

def install
fails_with_llvm "Breaks with LLVM"

# Head and stable have different code layouts
src = File.exists?('src/Makefile') ? 'src' : '.'
system "make -C #{src}"

%w( redis-benchmark redis-cli redis-server redis-check-dump redis-check-aof ).each { |p|
bin.install "#{src}/#{p}" rescue nil
}

%w( run db/redis log ).each { |p| (var+p).mkpath }

# Fix up default conf file to match our paths
inreplace "redis.conf" do |s|
s.gsub! "/var/run/redis.pid", "#{var}/run/redis.pid"
s.gsub! "dir ./", "dir #{var}/db/redis/"
end

doc.install Dir["doc/*"]
etc.install "redis.conf"
(prefix+'io.redis.redis-server.plist').write startup_plist
end

def caveats
<<-EOS.undent
If this is your first install, automatically load on login with:
cp #{prefix}/io.redis.redis-server.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

If this is an upgrade and you already have the io.redis.redis-server.plist loaded:
launchctl unload -w ~/Library/LaunchAgents/io.redis.redis-server.plist
cp #{prefix}/io.redis.redis-server.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/io.redis.redis-server.plist

To start redis manually:
redis-server #{etc}/redis.conf

To access the server:
redis-cli
EOS
end

def startup_plist
return <<-EOPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>#{bin}/redis-server</string>
<string>#{etc}/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>#{`whoami`.chomp}</string>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/redis.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/redis.log</string>
</dict>
</plist>
EOPLIST
end
end
(10) 刪除全部軟件升級後的遺留舊版本
$ brew cleanuppython

相關文章
相關標籤/搜索