As I just explained in my last post, the last version of R —3.4.4 “Someone to Lean on”— was rolled out las Thursday and this time I was the one that updated the Homebrew’s formula to reflect the new version. I just decided to give it a try and update for first time a Homebrew’s formula since no one had updated it yet on Thursday afternoon and this way I would be able to install the new version with Homebrew.
As I’ve already mentioned, I really encourage anyone to contribute to Homebrew’s community and try to keep the formulae update. Homebrew also encourage this, since as more people keep an eye on formula and update them, the better for the community.
How can you update a Homebrew formula?
The first and foremost important thing is to check if someone already filed a pull request for that same formulae, or in other words, if that formula is in the process of being updated. If no one is updating that formula, it’s opportunity to contribute and update it for the benefit of the community.
Before you begin, you need to update Homebrew to get the last version:
1 brew update
When you have the last version of Homebrew, you can edit your formula. If you just going to update the formula because there is a new version of the software that the formula installs, the best way to go is to use the script Homebrew provided to update formulae. In the case of R formula —r.rb— the syntax was as follows.
1 brew bump-formula-pr --strict R with --url=https://cran.r-project.org/src/base/R-3/R-3.4.4.tar.gz and --sha256=b3e97d2fab7256d1c655c4075934725ba1cd7cb9237240a11bb22ccdad960337
In this case, the URL and the sha256 was provided by Peter Dalgaard in the R 3.4.4 announcement. However, you have to take into account that https urls are preferred, so I had to recommit to follow that guidelines.
If you don’t have the sha256, you can calculate it yourself downloading the file and then running the following command that for me was as follows:
1 openssl sha -sha256 ~/Downloads/R-3.4.4.tar.gz
When you have those two parameters, you are ready to run the command. What the command does is basically create a fork of Homebrew in your account of Github, and then create a branch where it’s going to upload the modified formula. Then, it just makes a pull request to Homebrew/homebrew-core. If everything is ok, they’ll accept your changes and the new formula will be accessible to everyone after they run
$ brew update. On the other hand, if you have to make modifications in the formula you are submitting in your pull request —as I needed to make— you just do them using Git.
1 2 3 cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core # go to your local repo for Homebrew git branch # here you select the branch with the name of the update you are creating brew edit R # your preferred editor with open
Now, you can make the necessary changes and when you are done you just save the file and
1 2 3 git add R.rb # in this specific case git commit -m "fixed the previous error" git push YourForkOfTheRepo TheNameOfTheBranch
If you want to test your version of the formula this is easy, you just stay in the branch where the modified formula is and run:
1 brew upgrade R
## Use someone else’s formula
You can even use this updated formula to update the R of someone computer while they accept your pull request —if you are in a hurry or you are antsy guy. To do so you can use hub.
1 2 3 4 brew install hub brew update cd $(brew --repository) hub pull someone_else
Or you can directly install the formula that is their repo in GitHub:
1 brew install https://raw.github.com/user/repo/branch/formula.rb
In my case:
1 brew install https://github.com/luisspuerto/homebrew-core/blob/r-3.4.4/Formula/r.rb
Or pull the formula from the pull request:
1 brew pull https://github.com/Homebrew/homebrew-core/pull/1234
In my case:
1 brew pull https://github.com/Homebrew/homebrew-core/pull/25321
However, I don’t recommend you to do something like this and install the someone’s formula unless you really know the person. You never know what it’s in the install script. Usually, pull request are resolved within hours and it’s much better practice to wait until the Homebrew maintainers review the updated formula and approve it.
Leave a comment