129

I would like to install the older version of Google Protocol Buffers (protobuf-2.4.1) on Mac using the command line/Terminal app.

I tried with brew install protobuf, but the latest version 2.5.0 has been installed.

Is it possible to install the older version from the terminal?

3
  • 2
    Why do you want an older version? They are backwards-compatible, as long as you regenerate the .pb.h and .pb.cc files. Feb 15, 2014 at 5:40
  • I thought I better use the old version as the project was build with 2.4.1. But as you said I have regenerated the the two files and it works fine. Thanks. Feb 17, 2014 at 14:14
  • 4
    And in general, here is how to install a specific version of a formula.
    – Duvrai
    Feb 24, 2014 at 8:40

16 Answers 16

156

There are some issues with building protobuf 2.4.1 from source on a Mac. There is a patch that also has to be applied. All this is contained within the homebrew protobuf241 formula, so I would advise using it.

To install protocol buffer version 2.4.1 type the following into a terminal:

brew tap homebrew/versions
brew install protobuf241

If you already have a protocol buffer version that you tried to install from source, you can type the following into a terminal to have the source code overwritten by the homebrew version:

brew link --force --overwrite protobuf241

Check that you now have the correct version installed by typing:

protoc --version

It should display 2.4.1

6
  • 4
    Hey I tried this, howeever on protoc --version i get -bash: protoc: command not found
    – ramin
    Jul 3, 2015 at 14:53
  • Version 2.4.1 is installed at "/usr/local/Cellar/protobuf241/2.4.1", you should just create a symlink of "../2.4.1/protoc" and put it in "/usr/local/bin". Try than "protoc --version" and should work exactly how it should. Dec 16, 2015 at 6:12
  • 4
    That tap isn't available any more Jun 21, 2017 at 13:46
  • 33
    Not working anymore. I get Warning: homebrew/versions was deprecated. This tap is now empty as all its formulae were migrated. Oct 19, 2017 at 15:40
  • 3
    it had migrated to core, use this instead: brew tap homebrew/homebrew-core Jun 3, 2020 at 8:10
108

This is not via brew, but the end result is the same.

  1. Download the protobuf-2.4.1 from https://github.com/protocolbuffers/protobuf/releases/tag/v2.4.1
  2. Extract the tar.gz file.
  3. $cd ~/Downloads/protobuf-2.4.1
  4. $./configure
  5. $make
  6. $make check
  7. $sudo make install
  8. $which protoc
  9. $protoc --version

Steps 4-7 are from the README.txt file from the protobuf tarball.

9
  • 2
    I tried the brew approach, but for the latest version of protobuf (now 2.6.0) it compiles easily from sources using the exact list of steps above. This becomes even more useful when trying to extend standard proto definitions (e.g., adding field options by extending descriptor.proto) as you need the original sources or otherwise must refer to the Cellar path in the home-brew version of installation (ugly?).
    – Necro
    Mar 7, 2015 at 0:14
  • 6
    On running the make command I ended up with errors:3 errors generated. make[2]: *** [message.lo] Error 1 make[1]: *** [all-recursive] Error 1 make: *** [all] Error 2 Aug 19, 2016 at 9:25
  • 1
    This is the solution which worked for me. But see Xiaoqi Chu's reply when facing with the errors during make.
    – Amudhan
    Nov 10, 2016 at 12:17
  • 2
    steps 4-7 are at /protobuf/src/README.md, I wish it was in the README.md in the /protobuf directory
    – Kevin Zhao
    Feb 24, 2017 at 2:36
  • 6
    This worked for me the only change is that you need to download sources from github.com/google/protobuf/releases
    – r00tt
    Feb 27, 2017 at 22:15
39

If you landed here looking for how to install Protocol Buffers on Mac, it can be done using Homebrew by running the command below

brew install protobuf

It installs the latest version of protobuf available. For me, at the time of writing, this installed the v3.7.1

If you'd like to install an older version, please look up the available ones from the package page Protobuf Package - Homebrew and install that specific version of the package.

The oldest available protobuf version in this package is v3.6.1.3

1
  • 2
    But the OP specifically asks for installing old version. Mar 10, 2020 at 8:06
35

It's a new year and there's a new mismatch between the version of protobuf in Homebrew and the cutting edge release. As of February 2016, brew install protobuf will give you version 2.6.1.

If you want the 3.0 beta release instead, you can install it with:

brew install --devel protobuf
1
  • invalid option --devel Sep 24, 2022 at 14:06
14

For some reason I need to use protobuf 2.4.1 in my project on OS X El Capitan. However homebrew has removed protobuf241 from its formula. I install it according @kksensei's answer manually and have to fix some error during the process.

During the make process, I get 3 error like following:

google/protobuf/message.cc:130:60: error: implicit instantiation of undefined template 'std::__1::basic_istream<char, std::__1::char_traits<char> >'

  return ParseFromZeroCopyStream(&zero_copy_input) && input->eof();

                                                           ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:108:28: note: template is declared here

    class _LIBCPP_TYPE_VIS basic_istream;

                           ^

google/protobuf/message.cc:135:67: error: implicit instantiation of undefined template 'std::__1::basic_istream<char, std::__1::char_traits<char> >'

  return ParsePartialFromZeroCopyStream(&zero_copy_input) && input->eof();

                                                                  ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:108:28: note: template is declared here

    class _LIBCPP_TYPE_VIS basic_istream;

                           ^

google/protobuf/message.cc:175:16: error: implicit instantiation of undefined template 'std::__1::basic_ostream<char, std::__1::char_traits<char> >'

  return output->good();

               ^

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iosfwd:110:28: note: template is declared here

    class _LIBCPP_TYPE_VIS basic_ostream;

                           ^

(Sorry, I dont know how to attach code when the code contains '`' )

If you get the same error, please edit src/google/protobuf/message.cc, add #include <istream> at the top of the file and do $ make again and should get no errors. After that do $ sudo make install. When install finished $protoc --version should display the correct result.

1
  • 2
    This worked for me in macOS Catalina! Saved me hours, thank you!
    – Sunil L
    Sep 24, 2020 at 15:49
14

From https://github.com/paulirish/homebrew-versions-1 . Works for me!

brew install https://raw.githubusercontent.com/paulirish/homebrew-versions-1/master/protobuf241.rb
1
  • Note, it's always recommended to scan through the formulae when installing from unknown sources. I did that, it was safe. Mar 8, 2019 at 9:41
10

I used macports

sudo port install protobuf-cpp
8

To install Protocol Buffer (as of today version v3.7.0)

  1. Go to this website
  2. download the zip file according to your OS (e.g.: protoc-3.7.0-osx-x86_64.zip). This applies also to other OS.

  3. Move the executable in protoc-3/bin/protoc to one of your directories in PATH. In Mac I suggest to put it into /usr/local/bin

Now your good to go 💪🏾

(optional) There is also an include file, you can add. This is a snippet of the README.md

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/'.

Please refer to our official github site for more installation instructions:
https://github.com/protocolbuffers/protobuf
6
brew install --devel protobuf

If it tells you "protobuf-2.6.1 already installed": 1. brew uninstall --devel protobuf 2. brew link libtool 3. brew install --devel protobuf

5

There is another official way by Google, as mentioned by another user.

Read it fully before trying.

Here are the steps:

Open Terminal and type the following

  1. PROTOC_ZIP=protoc-3.7.1-osx-x86_64.zip
  2. curl -OL https://github.com/google/protobuf/releases/download/v3.7.1/$PROTOC_ZIP
  3. sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
  4. rm -f $PROTOC_ZIP

Worked for me.

P.S.
This is for version 3.7.1 in osx only. If you want to install some other version/platform, visit the releases link and check out the details of the latest version, and use those information. Reference

1
2

FWIW., the latest version of brew is at protobuf 3.0, and doesn't include any formulae for the older versions. This is somewhat "inconvenient".

While protobuf may be compatible at the wire level, it is absolutely not compatible at the level of generated java classes: you can't use .class files generated with protoc 2.4 with the protobuf-2.5 JAR, etc. etc. This is why updating protobuf versions is such a sensitive topic in the Hadoop stack: it invariably requires coordination across different projects, and is traumatic enough that nobody likes to do it.

2

HomeBrew versions has been removed and formulaes have been emptied. Therefore, my advice is to install it manually following the following steps.

For the time being you will need to build and install the Protocol Buffers toolset manually.

  1. Download source code: https://github.com/google/protobuf/releases/download/v2.4.1/protobuf-2.4.1.tar.gz

  2. tar xvfz protobuf-2.4.1.tar.gz

  3. cd protobuf-2.4.1

  4. Run ./configure

  5. Edit src/google/protobuf/message.cc, add #include at the top of the file

  6. Run make command from root of the folder, i.e. protobuf-2.4.1/

  7. Run sudo make install

  8. Run /usr/local/bin/protoc --version to check the version of protobuf compiler version The terminal output should be:

    Version: libprotoc 2.4.1

0

you can install from official link page provided by google http://google.github.io/proto-lens/installing-protoc.html

0

For v3 users.

http://google.github.io/proto-lens/installing-protoc.html

PROTOC_ZIP=protoc-3.7.1-osx-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
0

There should be better ways but what I did today was:

  1. Download from https://github.com/protocolbuffers/protobuf/releases (protoc-3.14.0-osx-x86_64.zip at this moment)

  2. Unzip (double click the zip file)

  3. Here, I added a symbolic link

ln -s ~/Downloads/protoc-3.14.0-osx-x86_64/bin/protoc /usr/local/bin/protoc
  1. Check if works
protoc --version
0

The below link gives a clear idea on how to install a specific version of protobuf in a macbook.

https://makeoptim.com/en/tool/brew-install-specific-version/

1
  • The problem with URL only answers is that the link can go stale. Can you incorporate the details in this answer so it can stand-alone? Jun 6 at 22:12

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.