How can I install protoc, the protobuf compiler to generate Java, on Ubuntu 16.04?
6 Answers
See https://github.com/protocolbuffers/protobuf/blob/master/src/README.md:
Prerequesites
$ sudo apt-get install autoconf automake libtool curl make g++ unzip
Installation
- From this page, download the
protobuf-all-[VERSION].tar.gz. - Extract the contents and change in the directory
./configuremakemake checksudo make installsudo ldconfig # refresh shared library cache.
Check if it works
$ protoc --version
libprotoc 3.6.1
- 134
- 1
- 10
- 18,749
- 26
- 70
- 97
-
The same steps works fine for Ubuntu Trusty too. – Binita Bharati Feb 07 '19 at 09:48
-
11Also works on Ubuntu 18.04 – Binita Bharati Feb 08 '19 at 10:26
-
https://www.youtube.com/watch?v=EAFK-tN_yaw – Pushkarraj Pujari Apr 15 '19 at 06:45
-
5step 4: make -jX Where X is number of cores you have, to run in parallel – Omar Jun 12 '19 at 23:48
-
perfect for Debian 10 – Corrado Jul 10 '19 at 15:21
-
thank @OmarS. it really used my 4 cores CPU to compile =)) – Thai Tran Apr 13 '20 at 02:47
-
@MartinThoma `bash: ./configure: No such file or directory` – Bilal Feb 23 '21 at 05:24
-
@Bilal You probably didn't go into the directory. When you `ls`, can you see the file `configure`? If not, you did something wrong – Martin Thoma Feb 23 '21 at 05:30
-
@MartinThoma I went inside, I could see `configure.ac`, but I couldn't do `./configure` – Bilal Feb 23 '21 at 05:51
-
1@Bilal You need to [run autoconf](https://unix.stackexchange.com/a/158961/4784). Thanks for the comment! – Martin Thoma Feb 23 '21 at 06:06
sudo apt install protobuf-compiler
- 1,391
- 10
- 11
-
7It results in "Setting up protobuf-compiler (2.6.1-1.3)" - might not be the version everyone wants – y.selivonchyk Nov 01 '19 at 23:11
If you are a non-C++ user and/or don't want to compile it yourself, the simplest way to install the current version of protoc is to download a pre-built binary from the release page.
https://github.com/protocolbuffers/protobuf/releases
To install, simply place this binary somewhere in your PATH (e.g. /usr/local/bin).
(If you intend to use the included well known types then don't forget to copy the contents of the 'include' directory somewhere as well, for example into /usr/local/include/.)
Example:
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip
sudo unzip -o protoc-21.12-linux-x86_64.zip -d /usr/local bin/protoc
sudo unzip -o protoc-21.12-linux-x86_64.zip -d /usr/local 'include/*'
# now test:
protoc --version
-
You may also need some protos from [Google's Common API](https://github.com/googleapis/api-common-protos/tree/master/google/api) protos. Clone [the repo][4] and move the contents of `google` to `/usr/local/include/`. – Jack Apr 18 '20 at 15:11
-
protoc is not looking in /usr/local/include for me, at least by default. – Bryan May 08 '20 at 11:07
You can download binary from the source code and use next commands
sudo rm -rf ./protoc
unzip protoc-3.10.1-linux-x86_64.zip -d protoc
chmod 755 -R protoc
BASE=/usr/local
sudo rm -rf $BASE/include/google/protobuf/
sudo cp protoc/bin/protoc $BASE/bin
sudo cp -R protoc/include/* $BASE/include
Change your base to /usr/, or /usr/loca/, or anything else in your PATH.
- 160
- 8
1) Download binary from the url https://github.com/protocolbuffers/protobuf/releases
2) extract and keep the directory at particular location (/user/app/protoc)
3) add the entry in /usr//.bash_profile as
export PROTOC_HOME=/user/app/protoc
export PATH=$PROTOC_HOME/bin:$PATH
4) refresh file $source /usr/<username>/.bash_profile
Other option is run the following command one by one after downloading the repository :
sudo rm -rf ./protoc
unzip protoc-3.10.1-linux-x86_64.zip -d protoc
chmod 755 -R protoc
BASE=/usr/local
sudo rm -rf $BASE/include/google/protobuf/
sudo cp protoc/bin/protoc $BASE/bin
sudo cp -R protoc/include/* $BASE/include
- 111
- 3
Use this if you are having errors like
google/protobuf/descriptor.proto: File not found.
google/protobuf/duration.proto: File not found.
google/protobuf/timestamp.proto: File not found.
PROTOC_ZIP=protoc-3.7.1-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
This is useful when you are doing generation for go using protoc-gen-go as it requires the base proto files to be present in default include folders
- 2,030
- 8
- 20
- 27
- 11
- 1