Automated installation with Brew/cask in apps folder - bash

I want create an automated script to use on a post installation.
For this reason i want use brew and cask to make it all.
So, i think that my script should start with that to install brew:
echo << "Installing homebrew..."
if test ! $(which brew); then
echo "Homebrew not found, Installing..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
Then i need to install some useful stuff as i see here:
http://lapwinglabs.com/blog/hacker-guide-to-setting-up-your-mac
So i put this too on my script:
# Install GNU core utilities (those that come with OS X are outdated)
brew install coreutils
# Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
brew install findutils
# Install Bash 4
brew install bash
# Install more recent versions of some OS X tools
brew tap homebrew/dupes
brew install homebrew/dupes/grep
$PATH=$(brew --prefix coreutils)/libexec/gnubin:$PATH
After that, the guide on the link says to install all the apps with cask and clean.
Here is my question.
I wish install and can update them in future using the classical Application folder of mac
How i can do that?
Maybe i should put this line:
export HOMEBREW_CASK_OPTS="--appdir=/Applications --caskroom=/usr/local/Caskroom"
Before all the commands to install the apps? May it works? (I have found this line here around)
If this line is correct can I update my apps using a brew/cask command?
Sorry for the dumbs questions, I've just discovered brew and cask yesterday :)
Any suggestion or example for this script is well accepted :)

brew cask install <formula> is supposed to symlink your app in Applications automatically.

Related

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)

I use the latest Apple M1 chip processor. And I keep getting errors while application installation.
say.,
brew install openjdk#11
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
https://docs.brew.sh/Installation
You can migrate your previously installed formula list with:
brew bundle dump
Need help with exact steps to follow.
For what it's worth, before installing Homebrew you will need to install Rosetta2 emulator for the new ARM silicon (M1 chip). I just installed Rosetta2 via terminal using:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
This will install rosetta2 with no extra button clicks.
After installing Rosetta2 above you can then use the Homebrew cmd and install Homebrew for ARM M1 chip: arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Once Homebrew for M1 ARM is installed use this Homebrew command to install packages: arch -x86_64 brew install <package>
Homebrew needs to be installed in two places on Apple silicon: in /usr/local for rosetta-emulated (Intel) code, and /opt/homebrew for ARM64. These are somewhat hard-coded and the /opt/homebrew one MUST be used for ARM code, as it stands today, and is non-negotiable. However, it's easy enough to install and you can follow the general instructions on the official docs. You open a Rosetta shell first.
% arch -x86_64 zsh
% cd /usr/local && mkdir homebrew
% curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Later, to install tools under intel you can use the arch command per-command or open a zsh terminal as above.
arch -x86_64 /usr/local/homebrew/bin/brew install sometool
For the ARM architecture, you don't need to use arch but you do need to use the full path of the homebrew command.
/opt/homebrew/bin/brew install sometool
You could rename the brew commands to something like brew86 and brewARM to help keep them separate.
Run this in the terminal it fixes the issue
eval "$(/opt/homebrew/bin/brew shellenv)"
Just use:
arch -arm64 brew install package-name
replace 'package-name' with the package you want to install.
Did a temporary fix by enabling Open using Rosetta option in the terminal app from Utilities folder.
However, it would be great to know the actual solution for this question to use the native way.
There is a lot of helpful info in the replies here, but there doesn't seem to be a direct answer to the original request, "Need help with exact steps to follow."
In case it may help people facing this issue in the future, I'll share the exact steps that I followed to resolve the issue.
The following CLI commands are intended to be run on an Apple silicon-equipped Mac in the built-in Terminal application running the macOS-default shell, Zsh:
Run a Homebrew command to confirm that an error like the following appears:
$ brew install <formula>
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
Please create a new installation in /opt/homebrew using one of the
"Alternative Installs" from:
https://docs.brew.sh/Installation
Or:
$ brew doctor
Warning: Your Homebrew's prefix is not /opt/homebrew.
Some of Homebrew's bottles (binary packages) can only be used with the default
prefix (/opt/homebrew).
You will encounter build failures with some formulae.
If either of these errors appears, it is likely that the steps below are applicable to your case.
Navigate to the /opt folder:
$ cd /opt
Create a folder named homebrew. By default superuser privileges are required to write inside of the /opt folder, which means that it is necessary to use sudo:
$ sudo mkdir homebrew
Grant write access to the homebrew folder so that your user can perform the Homebrew installation:
$ sudo chmod go+w homebrew
Perform the four steps listed on the "Alternative Installs" page (the page mentioned in the first error message in step 1):
Install Homebrew:
$ curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
Set Homebrew's prefix in your current Terminal session:
$ eval "$(homebrew/bin/brew shellenv)"
Update Homebrew:
$ brew update --force --quiet
Revoke write access to specific folders and files:
$ chmod -R go-w "$(brew --prefix)/share/zsh"
Set Homebrew's prefix in future Terminal sessions by adding the necessary command to one of Zsh's startup files. As far as I can tell, .zshrc is the preferred startup file for this type of command:
$ echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
Note that if there are any other existing Terminal sessions on your machine that have been open since before running the above command, the correct Homebrew prefix will still be unset in those sessions.
Confirm that Homebrew's prefix is now properly set:
$ type -a brew
brew is /opt/homebrew/bin/brew
brew is /usr/local/bin/brew
Or:
$ brew doctor
Your system is ready to brew.
It should now be possible to continue using Homebrew normally.
This issue with new macbook pro M1 chip
Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
For Resolve follow below steps
Step1
$ brew bundle dump
Step2
$ /bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step3
Edit file below
$ vi ~/.bashrc or vi ~/.zshrc
Edit below line in above file
export PATH=/opt/homebrew/bin:$PATH
Homebrew is now available for the new apple M1 chip at https://docs.brew.sh/Installation. The script installs in a new location, ‘/opt/homebrew’ instead of ‘/usr/local’ which requires that you implement a couple lines of script after the install, substituting your username. You can copy/paste from the comments in your install. Just don’t skip these steps.
==> Next steps:
- Add Homebrew to your PATH in /Users/[username]/.zprofile:
echo 'eval "$(/opt/homebrew/bin/brew [username])"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew [username])"
Note: This works for a clean install of Homebrew on a new machine. If you have already installed an old version of Homebrew and got it working, I believe you need to uninstall that first -or- you may find this a quicker work-around http://blog.wafrat.com/homebrew-on-mac-with-m1/. Not tested.
See: https://docs.brew.sh/Installation
1. Clone homebrew
$ cd /opt
$ sudo git clone https://github.com/Homebrew/brew homebrew
2. Chown dir
$ sudo chown -R $(whoami):staff /opt/homebrew
3. Update new brew shellenv temporarily, more shellenv meaning see man brew
$ eval "$(homebrew/bin/brew shellenv)"
4. New brew update
$ brew update --force --quiet
==> Homebrew has enabled anonymous aggregate formula and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).
==> Tapping homebrew/core
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1265097, done.
remote: Counting objects: 100% (207/207), done.
remote: Compressing objects: 100% (97/97), done.
remote: Total 1265097 (delta 120), reused 192 (delta 110), pack-reused 1264890
Receiving objects: 100% (1265097/1265097), 517.64 MiB | 3.02 MiB/s, done.
Resolving deltas: 100% (872476/872476), done.
Tapped 3 commands and 6273 formulae (6,616 files, 566.4MB).
5. Make sure remove other person write privage
$ chmod -R go-w "$(brew --prefix)/share/zsh"
6. Confirm new brew version
$ brew --version
Homebrew 3.6.0
Homebrew/homebrew-core (git revision 57f5c02ec6a; last commit 2022-09-10)
7. Brew config show
/opt/homebrew on  stable (93ea8cb2c) 💰 17:17:54
$ brew config
HOMEBREW_VERSION: 3.6.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 93ea8cb2c40e1ef25f1489b0267526bd47bc8030
Last commit: 3 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 57f5c02ec6af877482ecd8753066d6a277cd3213
Core tap last commit: 72 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_REPOSITORY: /opt/homebrew
HOMEBREW_CELLAR: /opt/homebrew/Cellar
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: 10-core 64-bit westmere
Clang: 13.1.6 build 1316
Git: 2.32.1 => /Applications/Xcode.app/Contents/Developer/usr/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.5.1-x86_64
CLT: 13.4.0.0.1.1651278267
Xcode: 13.4.1
Rosetta 2: true
8. Add new brew shellenv to strart bash shell, eg. ~/.zshrc、~/.barshrc etc.
eval "$(/opt/homebrew/bin/brew shellenv)"
This also may occur if you are trying to run your command in IntelliJ Terminal. Just try to run in (Regular) Terminal.
First run this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
then it will ask you a question, hit return, then wait for the installation to be completed. After than run this command:
brew bundle dump
Go over to https://brew.sh and use the command. It will download and install brew again correctly.
Run this command as this will resolve the issue
arch -arm64 brew install kotlin
I had installed Homebrew using iTerm enabled for the Apple ARM chip (M1), but when using a different terminal program that was Intel-based (and thus opening in Rosetta) I got this error. The latter app is seen as Intel, and thus wants to use the older Homebrew path.
Probably this error is related running brew on M1/M2 Mac instead instead of Intel based Mac, atleast that was in my case. I had previously restored a Time Machine backup from Intel to M2.
According to the Homebrew documentation, the default installation script installs Homebrew to its preferred /usr/localfor macOS Intel and /opt/homebrew for Apple Silicon.
You can well use this, as it worked well for me-
re-install brew by running this in your terminal /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
run brew bundle dump
You should be good on using brew
So I bought a new M1 and migrated to it. I took it back and migrated back. I was receiving this error. Found that I needed to run sudo rm -Rf /opt/homebrew after re-installing brew to get things flowing again. 16G Ram on the M1 didn't replace my workflow with Intel using 64G.

How to install apps with homebrew in OS X

i want to install virtual box on mac os EI Captain with homebrew and also if i want to install more packages with homebrew how can i know that package is available in homebrew?
Thanks
First, you’ll need the command-line tools for Xcode installed. On a modern Mac OS X system, you can install these just by running the following command in a Terminal window. You could also install the full Xcode application from Apple, if you prefer — but that takes up more space on your Mac and isn’t necessary.
xcode-select --install
Next, install Homebrew. You can just open a Terminal window, copy-paste the following command, and press Enter:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
This script informs you what it will do. Press Enter and then provide your password to install it. By default, it installs Homebrew so you can use the brew command without typing the sudo command and providing your password.
Run the following command once you’re done to ensure Homebrew is installed and working properly:
brew doctor
Once you’re done, run the following command to install Homebrew Cask. It uses Homebrew to install Cask:
brew install caskroom/cask/brew-cask
Now you can install the Virtual box by entering the following commands
brew install vagrant-completion
brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager
For knowing that your package is available or not you can search your desire package by the following commands
For Open-Source Utilities
brew search name-of-your-package
For graphical Apps
brew cask search name-of-your-app
For installing Graphical Apps run
brew cask install name-of-your-app
For installing Open-Source Utilities run
brew install name-of-your-package

Detect if homebrew package is installed

I'm about to write a shell script to detect if several homebrew packages are installed in the system. Is there a way to use a brew command to achieve that?
I tried using the exit code of brew install <formula> --dry-run. But this builds the package if it is missing.
You can use
brew ls --versions myformula
to output the installed versions of the respective formula. If the formula is not installed, the output will be empty.
When using a recent versions of homebrew, which you can get with brew update, you can just run this (thanks Slaven):
if brew ls --versions myformula > /dev/null; then
# The package is installed
else
# The package is not installed
fi
That said, it is probably a good idea to check for the existence of the tool at all and not just checking for the respective homebrew package (e.g. by searching for the executable in the $PATH). People tend to install tools in a rather large amount of ways in practice, with homebrew being just one of them.
# install if we haven't installed any version
brew ls --versions $lib || brew install $lib
# install if we haven't installed latest version
brew outdated $lib || brew install $lib
What about?
for pkg in macvim ngrep other needed packages; do
if brew list -1 | grep -q "^${pkg}\$"; then
echo "Package '$pkg' is installed"
else
echo "Package '$pkg' is not installed"
fi
done
Easiest two-liners:
Step one, make sure it's installed
$ realpath . || brew install coreutils
This will print out the realpath of current dir, if not, then it will install it.
And it will not fail even realpath not found.
Step two, call it in your actual code:
$ realpath ${someDir}
For script and automation usage, I found out that brew bundle --help is very convenient.
If you do not want to use real bundle file, this snippet works fine in scripts:
brew bundle -v --file=- <<-EOF
brew "mc"
brew "ffmpeg"
brew "wget"
cask "cpuinfo"
cask "intel-power-gadget"
cask "unetbootin"
cask "vlc"
EOF
The good side of it, it will automatically detect if package is not installed, if it is outdated and only then will install it.
If you do not want updates, add a flag --no-upgrade. I have put -v for verbosity, as want more details, but you can skip it, or even use -q for even more silent run.

How can I install GNU Octave on Mac with Fink ?

I tried to install GNU Octave on my Mac using Fink by this instruction
http://wiki.octave.org/Octave_for_MacOS_X
I think I have followed all the instructions but I can't run Octave.
How can I check if it is installed correctly?
I tried typing 'octave' in the terminal but it says 'command not found'
Or, is there any easy instruction for Octave installation?
I've found many install guides but they are all different and assumes some knowledge.
Incidentally, I have installed Octave GNU today twice on two different machines (both running Lion).
I needed the latest version of Octave (3.6.4), and used Homebrew.
I already had XCode installed, so the rest:
Install Homebrew
Based on the instructions in this page, I ran:
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Install Octave
Following this guide, I ran:
brew tap homebrew/science
brew update && brew upgrade
brew install gfortran
brew install octave
Install AquaTerm
Notice that you need this before you install gnuplot (or gnuplot won't see aqua as a valid terminal and you may get 'unknown or ambiguous terminal type' error).
Simply downloaded the latest version (1.1.0) dmg from SourceForge.
Install gnuplot
brew install gnuplot
You could try installing it with Home Brew. Once you download and install Home Brew, use this guide to get Octave installed.
Easiest option would be using the precompilled .app
I've tried the precompiled .app, but had issues with certain functions (like sound),
whereas the macports version always worked.
I usually install it using macports:
sudo port install octave
for the basics.
You might need other port variants/octave modules installed:
sudo port install octave octave-signal octave-plot octave-image octave-signal
Need to have XCode with Command Line Tools first and Macports with this route though
How to know if a Fink package is installed
By default (and this should be your case too if you didn't changed it), Fink installs everything under /sw, i.e. the binaries you are looking for should be in /sw/bin/.
Run ls /sw/bin/octave*and, depending on the output, you then have two choices :
Either the Octave binary is inside /sw/bin, in that case run echo $PATH and learn more about PATH Variable to fix your problem.
Otherwise, if there is nothing inside, there might have been a problem with the install. Try running fink install octave once more, look closely at the output and update your post if necessary.
This is simply an update on the instruction provided by Izhaki (that I ran on Mac OSX 10.8.4).
You may be required to update XCode to 4.6.3. This can be done through the AppStore.
If you encounter the error:
Error: Download failed: http://threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb41_20130613oss_src.tgz
during
brew install octave
Then invoke:
brew update
brew install octave
and the install will pick up where it left off. Other than that, the instruction worked seamlessly.

How to install JSON.pm perl module on OSX

I am trying to use the po2json parser/converter from the JS gettext library (http://jsgettext.berlios.de/), but when I try to convert I get this error:
Can't locate JSON.pm in #INC (#INC contains: /Library/Perl/5.12/darwin-thread-multi-2level /Library/Perl/5.12 /Network/Library/Perl/5.12/darwin-thread-multi-2level /Network/Library/Perl/5.12 /Library/Perl/Updates/5.12.4 /System/Library/Perl/5.12/darwin-thread-multi-2level /System/Library/Perl/5.12 /System/Library/Perl/Extras/5.12/darwin-thread-multi-2level /System/Library/Perl/Extras/5.12 .) at ./po2json line 23.
BEGIN failed--compilation aborted at ./po2json line 23.
As far as I understand I am missing a perl module, namely JSON.pm, an I think it's this one: http://cpansearch.perl.org/src/MAKAMAKA/JSON-2.53/lib/JSON.pm
Now, how do I install it on OSX? I am using Mountain Lion.
I tried to do cpan install JSON, but it doesn't work, I get the following error:
Writing Makefile for JSON
MAKAMAKA/JSON-2.53.tar.gz
make -- NOT OK
'YAML' not installed, will not store persistent state
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Use homebrew to install cpanm:
brew install cpanm
Then you can install JSON with
sudo cpanm install JSON
The output said that make didn't return success. Probably due to some dependency.
Try using cpanm http://search.cpan.org/~miyagawa/App-cpanminus-1.5017/bin/cpanm, it's really hassle free and bootstrapped quite well (no need to install other stuff).
Install using this:
curl -L http://cpanmin.us | perl - --sudo App::cpanminus
cpan install JSON Having the JSON in all caps made it work for me.
I know this is an old topic, but wanted to share my solution after finding that I needed JSON when trying to use zap2xml (perl based). I was getting the error: "Can't locate JSON.pm in #INC..." after installing perl via Homebrew.
This is how I installed JSON via Homebrew. I will also include the steps required to install Homebrew (for those who would like to know). ;)
Prerequisites:
Install Xcode from the App Store (Download):
https://itunes.apple.com/us/app/xcode/id497799835
Install Command Line Tools for Xcode (Run in Terminal):
xcode-select --install
Install Homebrew (Run in Terminal):
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update Homebrew (Run in Terminal):
brew update
brew upgrade
brew doctor (correct issues found by brew doctor. Instructions will be given by The Doctor. :P)
Install cpanminus (Run in Terminal):
brew install cpanm
Check perl (Run in Terminal):
which perl
perl -V (with a capital -V)
Check/Install JSON module (Run in Terminal):
sudo cpanm -v JSON
DONE.
Following worked for me:
Run on terminal:
sudo perl -MCPAN -e shell
you should get the cpan shell prompt and run below commond at cpan shell:
cpan[1]> install JSON
Regards,
Anand Choubey
this way is OK, Follows the Command:sudo apt-get install libjson-perl

Resources