{"id":1383,"date":"2018-03-19T12:06:34","date_gmt":"2018-03-19T12:06:34","guid":{"rendered":"http:\/\/sophyonline.com\/blog\/?p=1383"},"modified":"2020-11-09T20:14:14","modified_gmt":"2020-11-09T20:14:14","slug":"create-a-local-formula-for-homebrew-tap-it","status":"publish","type":"post","link":"http:\/\/sophyonline.com\/blog\/2018\/03\/create-a-local-formula-for-homebrew-tap-it\/","title":{"rendered":"Create a local formula for homebrew (tap it!)"},"content":{"rendered":"<p>Before we dive in all the steps needed on how to create a formula, that you will use locally (ergo, not uploading it to homebrew public list), let&#8217;s briefly explain what is\u00a0<code>tap<\/code>\u00a0and <code>formula<\/code> in Homebrew.<\/p>\n<p>Formula:<\/p>\n<blockquote><p>A formula is a package definition written in Ruby.\u00a0A formula provides instructions and metadata for Homebrew to install a piece of software.<\/p><\/blockquote>\n<p>So basically a formula is a Ruby file, needed to install and run whatever you want in your machine. It links to a repo path, (yours). Doing a <code>brew create xxxx.tar.gz<\/code> creates the formula (Ruby file), the <code>tar.gz<\/code> is the zipped link of the project with the code you want to install in your machine (your repo); this gets clear in the steps bellow.<\/p>\n<p>Tap:<\/p>\n<blockquote><p>A Git repository of\u00a0Formulae and\/or commands<\/p><\/blockquote>\n<p>This is how homebrew makes the reference or connection of your github repo referred in your formula (the ruby file) and saves it in a retrievable path:<\/p>\n<p><code>\/usr\/local\/Homebrew\/Library\/Taps\/homebrew\/homebrew-core\/Formula\/YOUR-RUBY-FORMULA-HERE<\/code><\/p>\n<p>Ok, so let&#8217;s begin!<\/p>\n<h2>Steps to reproduce:<\/h2>\n<p>1.- create a github repo where you are going to place the script or file you will like to run in brew <code>for example: unsign-xcode<\/code><\/p>\n<p>2.- add the file where your script is to the repo (don\u2019t add file extension) and also grantpermission to it: <code>chmod +x<\/code> and push the commit. I\u2019ve created a file called <code>unsign-xcode<\/code> for this example.<\/p>\n<p>3.- add a tag version to the file: <code>v1.0.0<\/code> (for example) and push the tag<\/p>\n<p>4.- go to releases in your repo page in GitHub, select tags and in the section <code>tar.gz<\/code> right click and select <code>\u201cCopy link address\u201d<\/code><\/p>\n<p>5.- now, create the <em>formula<\/em> (repeat this step everytime you update the version from the files in this repo), this step will create the Ruby file mentioned before:<\/p>\n<pre><code>  brew create (paste the link copied before) <\/code><\/pre>\n<p>For example:<\/p>\n<pre><code>  brew create https:\/\/github.com\/phynet\/unsign-xcode\/archive\/v1.0.0.tar.gz<\/code><\/pre>\n<p>6.- next, it&#8217;s turn to create a new repo, this time for the <em>homebrew formula<\/em> created in step 5. In this case will be called: <code>homebrew-unsign-xcode<\/code><\/p>\n<p>7.- clone it empty and try to move the ruby file created in step 5 to this new repo. The formula file is located in:<\/p>\n<pre><code>\/usr\/local\/Homebrew\/Library\/Taps\/homebrew\/homebrew-core\/Formula\/unsign-xcode.rb<\/code><\/pre>\n<p>8.- open the file and edit it removing the line where <code>test<\/code> text is placed and leave only the code with <code>install<\/code>, there&#8217;s where you&#8217;re going to add <code>bin.install<\/code> with the name of the file:<\/p>\n<pre><code>   def install\n     bin.install \"unsign_xcode\"\n   end<\/code><\/pre>\n<p>9.- add the file to git, commit and push<\/p>\n<p><strong>Note: from here, this steps are going to be similar to any homebrew process to install code<\/strong><\/p>\n<p>10.- once pushed go to terminal and tap it using a reference to the repo from step 1<\/p>\n<pre><code>    brew tap phynet\/unsign-xcode<\/code><\/pre>\n<p>11.- now try to install using brew command<\/p>\n<pre><code>    brew install unsign-xcode<\/code><\/pre>\n<p>11.1.- if a message like this one appears:<\/p>\n<pre><code>    Error: unsign-xcode 1.0.3 is already installed\n    To upgrade to 1.0.4, run `brew upgrade unsign-xcode`<\/code><\/pre>\n<p>run the command brew update and it will automatically update to the tag version for the repo updated before.<\/p>\n<p>12.- To use it type the command:<\/p>\n<pre><code class=\"language-bash\"> unsign-xcode<\/code><\/pre>\n<p>And there you have it \ud83d\ude00<\/p>\n<p>BTW: this is the repo for my unsign-xcode command. https:\/\/github.com\/phynet\/unsign-xcode.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before we dive in all the steps needed on how to create a formula, that you will use locally (ergo, not uploading it to homebrew public list), let&#8217;s briefly explain what is\u00a0tap\u00a0and formula in Homebrew. Formula: A formula is a package definition written in Ruby.\u00a0A formula provides instructions and metadata for Homebrew to install a <a class=\"read-more\" href=\"http:\/\/sophyonline.com\/blog\/2018\/03\/create-a-local-formula-for-homebrew-tap-it\/\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[3,30],"tags":[33,32,31],"class_list":["post-1383","post","type-post","status-publish","format-standard","hentry","category-development","category-homebrew","tag-create-formula","tag-formula","tag-homebrew"],"_links":{"self":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/1383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/comments?post=1383"}],"version-history":[{"count":21,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/1383\/revisions"}],"predecessor-version":[{"id":1465,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/posts\/1383\/revisions\/1465"}],"wp:attachment":[{"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/media?parent=1383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/categories?post=1383"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sophyonline.com\/blog\/wp-json\/wp\/v2\/tags?post=1383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}