Saturday, August 17, 2013

How to install 'brew' packages manually.

Currently when I use my 'brew' to upgrade, I got some errors that I can't download the packages from github. 

The error messages are something like this:

==> Upgrading 1 outdated package, with result:
macvim 7.4-70
==> Upgrading macvim
==> Downloading https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz
####################################                                      50.0%
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
==> Trying a full download
##                                                                         3.7%
curl: (56) SSL read: error:00000000:lib(0):func(0):reason(0), errno 54
Error: Download failed: https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz


I don't know why but it seems that 'curl' just can't download the packages from github.

So I want to install the package manually:

1) Download 'https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz' manually. So now I have '~/Download/macvim-snapshot-70.tar.gz'.

2) Verify it is the right one (this step is optional, but highly recommended):
 - Open '/usr/local/Library/Formula/macvim.rb' and we can see that the files's sha1 checksum should be '66432ae0fe81b2787b23343b6c99ef81f6b52c3e'
 - Use 'shasum' (a command line tool comes with the system) to check the downloaded file, it should output the same checksum.

3) Now open 'usr/local/Library/Homebrew/download_strategy.rb', add a line:
 (it should start at line 62)
  # Private method, can be overridden if needed.
  def _fetch
    ohai "download to #{@temporary_path}"
    curl @url, '-C', downloaded_size, '-o', @temporary_path
  end


4) Run 'brew upgrade' again. It will fail, but it will also print more information we need:
==> Upgrading 1 outdated package, with result:
macvim 7.4-70
==> Upgrading macvim
==> Downloading https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz
==> download to /Library/Caches/Homebrew/macvim-7.4-70.tar.gz.incomplete
##                                                                         3.6%
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
==> Trying a full download
==> download to /Library/Caches/Homebrew/macvim-7.4-70.tar.gz.incomplete
####                                                                       6.2%
curl: (56) SSL read: error:00000000:lib(0):func(0):reason(0), errno 54
Error: Download failed: https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz


Note the red line, now we know the file name should be 'macvim-7.4-70.tar.gz.incomplete'. So we just copy the file here.

5) cp ~/Download/macvim-snapshot-70.tar.gz /Library/Caches/Homebrew/macvim-7.4-70.tar.gz.incomplete

6) edit 'usr/local/Library/Homebrew/download_strategy.rb' again, comment the line after when added:
  # Private method, can be overridden if needed.
  def _fetch
    ohai "download to #{@temporary_path}"
    # curl @url, '-C', downloaded_size, '-o', @temporary_path
  end


7) Run 'brew upgrade' again.  Succeed!
==> Upgrading 1 outdated package, with result:
macvim 7.4-70
==> Upgrading macvim
==> Downloading https://github.com/b4winckler/macvim/archive/snapshot-70.tar.gz
==> download to /Library/Caches/Homebrew/macvim-7.4-70.tar.gz.incomplete
==> ./configure --with-features=huge --enable-multibyte --with-macarchs=x86_64 --enable-perlinterp --enable-rub
==> make
==> Caveats
MacVim.app installed to:
  /usr/local/Cellar/macvim/7.4-70

To link the application to a normal Mac OS X location:
    brew linkapps
or:
    ln -s /usr/local/Cellar/macvim/7.4-70/MacVim.app /Applications
==> Summary
🍺  /usr/local/Cellar/macvim/7.4-70: 1796 files, 28M, built in 74 seconds




Thursday, July 11, 2013

How to free the memory 'finder' use.

If you like me, that keep your mac run for several days, you may find that the 'finder' uses a lot of memory (sometimes more than 1GB).

Fortunately, you can 'relaunch' the finder to make it free the memory. Here is how to:

- hold the option key (alt)
- right click on the finder icon (on the dock)
- click 'relaunch'

The finder will remember how many windows it has, and their position and restore them after the relaunch.

Very usefuly :)