> For the complete documentation index, see [llms.txt](https://jun-wang.gitbook.io/learnjava/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jun-wang.gitbook.io/learnjava/kai-fa/huan-jing-da-jian/protobuffer-an-zhuang.md).

# ProtoBuffer安装

```
wget https://github.com/protocolbuffers/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
tar -zxvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
./configure 
make 
make check 
make install
```

## 问题1：非root用户不能安装

因为最后一步`make install`，因为安装在`/usr/local`下，需要root权限，所以普通用户无法安装，那么如何解决这个办法呢？就需要更改protobuf的安装路径了。

首先执行：

```
# 具体安装路径由你定义
./configure --prefix=/home/work/app/protobuf
```

这个其实影响的是Makefile文件中的`prefix`属性，当然你使用vim手动改Makefile也行。

如果是第一次执行make，那么就按照上面的步骤check,install进行，如果之前执行过make命令，那么先执行make clean然后执行make install。

完成后我们hu9i发现`/home/work/app/protobuf`这个目录下已经有protobuf了。

最后一步，配置环境变量`vim ~/.bash_profile`

```
PATH=$PATH:$HOME/app/protobuf/bin
```

将protobuf的bin目录放入环境变量。

重新`source .bash_profile`一下就好了。

## 问题2：protoc: error while loading shared libraries: libprotobuf.so.8: cannot open shared object file: No such file or directory

```
sudo ldconfig
```
