89

I installed ImageMagick via Homebrew.

However, due to a bug I have with my current configuration, I need to adjust the compile flags for the formula and reinstall it.

How can I accomplish this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
maček
  • 76,434
  • 37
  • 167
  • 198

2 Answers2

140

Remove the existing version.

$ brew rm imagemagick

Edit the formula.

$ brew edit imagemagick

This will bring it up in an editor; make sure your $EDITOR variable is set to your preference (for me: TextMate)

Change it, save it, try re-installing it.

Because most installs use pouring/bottles to install a precompiled binary, you will likely see no change unless you "build from source":

$ brew reinstall --build-from-source [...]

You can use --formula /path/to/imagemagick.rb as an additional argument to the above command to ensure brew is installing the formula that was edited.

If you're comfortable with git, you may also want to make a branch first, and do your edits in a branch to guard against data loss.

zcoop98
  • 2,590
  • 1
  • 18
  • 31
Adam Vandenberg
  • 19,991
  • 9
  • 54
  • 56
  • 3
    How do I change it back to the original version? Do I just have to run `brew upgrade`? – slhck Dec 15 '11 at 10:41
  • 1
    You change it back to the original version with git. `git checkout mysql.rb` may suffice if you didn't commit. If you committed you need to revert the commit. – mxcl Mar 03 '12 at 00:28
  • 1
    I have edited the formula but no 'install' method is being called from this file(tested by putting 'raise' statement just right in the beginning of the method) and imagemagick being installed successfully. I wonder what formula file does Homebrew use – ebsbk Apr 24 '14 at 15:26
  • 7
    To revert the edit you can use `git status` under `/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core` (or whichever tap you where using) and then do a a `git checkout ` – ccpizza Mar 04 '17 at 22:41
  • Also you can (without removing, just unlink) use "brew unlink ", then "brew edit " and set the app version manually; after that you need to just fetch/download app with command "brew fetch ", on result copy sha256 value, repeat brew edit and replace previous sha256 property. Then use "brew install ". Don't forget to reset formula state with command: "cd $(brew --repo)/Library/Taps/homebrew/homebrew-core/ ; git reset --hard HEAD" – ultraon Mar 16 '17 at 15:29
  • 7
    After `brew edit` use `brew reinstall --build-from-source`. Even if you edit it, most installs use `pouring bottle` to install a precompiled binary. Your changes won't have an effect. – Bruno Bronosky Feb 17 '20 at 10:08
  • 1
    @BrunoBronosky This comment is super useful and should probably be added to the accepted answer by the author. – valerio Aug 13 '21 at 20:05
  • 1
    @valerio done. It was originally a case of "this might work for you", but now that it's gotten some upvotes, I feel comfortable being more forward. Thanks. – Bruno Bronosky Aug 14 '21 at 11:24
  • 1
    @BrunoBronosky Great! Yeah, the original answer was not working for me, then I saw your comment, tried the command and it worked like a charm :) – valerio Aug 15 '21 at 19:03
  • Removing the package seems to be an unnecessary step. If you edit the formula and then do `reinstall --build-from-source` it will pick your changes up and reinstall the package with your changes. – galaxy Dec 12 '22 at 08:57
5

The accepted answer was the first step, but more was needed for my formula edit to work in February 2023.

If you edit formula foo, but your change is ignored by brew reinstall --build-from-source foo then, add export HOMEBREW_NO_INSTALL_FROM_API=1 to your shell config. It makes Homebrew actually use your revised formula.

Details: Homebrew FAQ: Edit Formula

Also, if you want your revised formula to persist, then run brew pin foo

Details: Homebrew FAQ: Prevent Formula Update/Upgrade

devdanke
  • 1,309
  • 15
  • 27
  • **NOTE** Homebrew v4.0 (February 2023) may have changed/fixed some problems with persistent custom formulas. Check v4 Release Notes for details: https://brew.sh/2023/02/16/homebrew-4.0.0/ – devdanke Jun 22 '23 at 10:25