protobuf的github地址:https://github.com/google/protobuf支持多种语言,有多个语言的版本,本文采用的是在CentOS 7下编译源码进行安装。linux
github上有详细的安装说明:https://github.com/google/protobuf/blob/master/src/README.mdgit
一、肯定centos7上已经安装了下面的软件,或者直接用yum进行更新github
autoconf automake libtool curl (used to download gmock) make g++ unzip
二、下载源码包,解压,编译安装centos
地址:https://github.com/google/protobuf/releasescurl
选择Source code (tar.gz)下载测试
tar -zxvf protobuf-3.1.0.tar.gz -C /usr/local/ cd protobuf-3.1.0/ # 若是使用的不是源码,而是release版本 (已经包含gmock和configure脚本),能够略过这一步 ./autogen.sh # 指定安装路径 ./configure --prefix=/usr/local/protobuf #编译 make # 测试,这一步很耗时间 make check make install # refresh shared library cache. ldconfig
注意make check这一步会花费比较多的时间google
三、设置一下环境变量 /etc/profileurl
# (动态库搜索路径) 程序加载运行期间查找动态连接库时指定除了系统默认路径以外的其余路径 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/protobuf/lib # (静态库搜索路径) 程序编译期间查找动态连接库时指定查找共享库的路径 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/protobuf/lib export PATH=$PATH:/usr/local/protobuf/bin
四、查看版本centos7
protoc --version
以后,对于相同的系统环境,就不须要再编译了,直接将编译好的protobuf(目录:/usr/local/protobuf)分发到其余计算机,设置环境变量便可code