<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: stldo</title>
    <description>The latest articles on DEV Community by stldo (@stldo).</description>
    <link>https://dev.to/stldo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F833798%2Fad6fe9ac-a3b8-4302-9e77-1aa5bfe20024.png</url>
      <title>DEV Community: stldo</title>
      <link>https://dev.to/stldo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stldo"/>
    <language>en</language>
    <item>
      <title>The missing update command for Homebrew</title>
      <dc:creator>stldo</dc:creator>
      <pubDate>Sun, 20 Mar 2022 23:03:44 +0000</pubDate>
      <link>https://dev.to/stldo/the-missing-update-command-for-homebrew-4fic</link>
      <guid>https://dev.to/stldo/the-missing-update-command-for-homebrew-4fic</guid>
      <description>&lt;p&gt;Homebrew is a great tool for managing packages in macOS. It allows to quickly install and update dozens of libraries and apps that otherwise would consume much more time to compile. Whenever I need an open-source package, most likely it'll be available in Homebrew. It's a really useful tool, but I rarely use it to a point that keeps it up-to-date. Every time I need to install something, Homebrew is outdated. So, to keep things simple, I came up with the following shell function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"update"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;brew update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew upgrade &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew autoremove &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew cleanup &lt;span class="nt"&gt;-s&lt;/span&gt;
  &lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;brew &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just copy and paste it to your &lt;code&gt;~/.zshrc&lt;/code&gt; file — or &lt;code&gt;~/.bashrc&lt;/code&gt;, if you use Bash — and every time you run &lt;code&gt;brew update&lt;/code&gt;, it'll run the following commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;brew update&lt;/code&gt;: updates the package definitions and Homebrew itself;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;brew upgrade&lt;/code&gt;: upgrades all the installed packages — &lt;code&gt;brew install&lt;/code&gt; upgrades any installed dependencies required by a package, but if it finds conflicts with outdated packages requiring the same libraries, you'll need to sort this out;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;brew autoremove &amp;amp;&amp;amp; brew cleanup -s&lt;/code&gt;: I started using this command after discovering a 50 GB Homebrew cache folder in my machine, it only takes a few seconds to run and keeps everything tidy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to execute this routine every time you call &lt;code&gt;brew install&lt;/code&gt;, you can use the following shell function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"install"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;brew update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew upgrade &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew autoremove &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew cleanup &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      brew &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;command &lt;/span&gt;brew &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the past, I used this function with the &lt;code&gt;brew install&lt;/code&gt; command, but now I prefer to use it with &lt;code&gt;brew update&lt;/code&gt;. Sometimes my Homebrew is really outdated and it takes some time until the update is done. I prefer to leave it running while I do other things, and then run &lt;code&gt;brew install package-name&lt;/code&gt; after everything went well. If you have any questions or know a better approach to keep Homebrew packages updated, please let me know, it'll be great to hear from you.&lt;/p&gt;

</description>
      <category>dx</category>
      <category>homebrew</category>
      <category>macos</category>
      <category>shell</category>
    </item>
  </channel>
</rss>
