I am trying to write a formula for homebrew to install a C++ tool I made. I have the following rule in my makefile to copy binaryFile file to /usr/local/bin:


    @install -m 0755 binaryFile /usr/local/bin

When I run make install, it correctly copies binaryFile to /usr/local/bin.

However, when I brew install the package, it gives the following error when running the make install:

install: /usr/local/bin/binaryFile: Operation not permitted
make: *** [install] Error 71

I have done some reading and most places say that, when given this error, use /usr/local/bin/ rather than /usr/bin - which is what I am already doing. I don't understand why when homebrew runs make install it behaves differently than when I manually run it.

To see the exact problem I'm having:

brew tap k-vernooy/tap
brew install terminalgol
  • You shouldn't install directly to /usr/local/bin. You should install to whatever prefix homebrew sets (which is usually, but no necessarily, somewhere in /usr/local). – muru Sep 12 '19 at 2:04
  • I set the install directory to $(brew --prefix)/bin, but it still returned the error Operation not permitted – k-a-v Sep 12 '19 at 2:52

You're not doing things right. A formula is forbidden to install binaries, or what ever, into /usr/local/bin directly.

As a formula, it should installed all of its content into a path like /usr/local/Celler/<formula-name>/<version>, which is called a prefix path and represented by #{prefix} in ruby. Homebrew will symlink the binary from subfolder bin/ under this #{prefix} into /usr/local/bin.

The #{prefix} variable from ruby is calculated by Homebrew automatically, following the pattern I mentioned above.

All you should do is to tell the configure file this prefix before compile and build.

class Wget < Formula
  homepage "https://www.gnu.org/software/wget/"
  url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz"
  sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd"

  def install
    system "./configure", "--prefix=#{prefix}"
    system "make", "install"

Please read the developer documentations and some existing formulae codes before you write your own formulae.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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