Chapter2 New Mac: Installing and Setup

Very Important!!!! When opening/starting a new mac for the first time always use the same account name and Home directory name. This will make the running of R code in either machine (folder and file locations) equal, and conflits or modification will be minimal.

MBP2015:
Account name: Marcelo-Rosales
Full Name: Marcelo Rosales
Home directory: /Users/Marcelo-Rosales

MBP2020: USE THIS BETTER From nowon!!! (Simpler to fill and set)
Account name: marcelorosales
Full Name: Marcelo Rosales
Home directory: /Users/marcelorosales


2.1 Install Homebrew

Why to Install Homebrew? Homebrew is a terminal program that helps to easily Install, Update, Upgrade, and Automate many tasks in Mac computers.
I used Mainly to migrate all my programs from one machine to another.

Formulae and Cask are small code snippets that need to be copy/paste or type into Mac Terminal to install a program.

An example of a “Cask formula”:

brew install --cask inkscape

You can search for the formulae and cask of a program in the homebrew webpage.

At the end of the installation, I will make a list of all the essencial programs (and some of the program settings like R and Atom) I need in a computer, and whenever I need to set up a new machine; Then, I will not have to install all the programs one by one again.

Install Homebrew.
(Video1)https://www.youtube.com/watch?v=1uvr9-zUB3w{target="_blank“}.
https://www.youtube.com/watch?v=-VP2NVv3LHg{target="_blank”}.

To Install Homebrew (on macOS or Linux) (https://brew.sh/){target=“_blank”}.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

More installation information and options: <(https://docs.brew.sh/Installation){target=“_blank”}>. If running Linux or WSL, there are some pre-requisite packages to install.

To Uninstall Homebrew link here

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

Download the uninstall script and run /bin/bash uninstall.sh –help to view more uninstall options.

Homebrew installs the stuff you need that Apple (or your Linux system) didn’t.

brew install wget

Update and upgrade, in brief, brew update updates Homebrew itself while brew upgrade will upgrade your Homebrew-installed software to their latest versions.Dec 2020:

brew update
brew upgrade

In my 2021Y-01M-02D upgrade and update an error occurred.
IF Error:
homebrew-core is a shallow clone.
To brew update, first run:

git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow

This restriction has been made on GitHub’s request because updating shallow clones is an extremely expensive operation due to the tree layout and traffic of Homebrew/homebrew-core and Homebrew/homebrew-cask. We don’t do this for you automatically to avoid repeatedly performing an expensive unshallow operation in CI systems (which should instead be fixed to not use shallow clones). Sorry for the inconvenience!

The run ( requires a long time to run )

Check if brew installed correctly with:

brew doctor

Usually it prompts Your system is ready to brew.

In my macbook pro 2015:
Warning: Homebrew’s sbin was not found in your PATH but you have installed formulae that put executables in /usr/local/sbin. Consider setting the PATH for example like… so run:

echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc

Warning: Your Xcode (11.7) is outdated.
Please update to Xcode 12.3 (or delete it).
Xcode can be updated from the App Store.

To check if a software/package is installed, and if not, then install

brew list <formulae1> || brew install <formulae1>

This will error on list and continue with install if not installed otherwise it will just list package files. (one could modify this further as a function or alias in .bashrc to make it easier to type)

From the tutorial
To confirm installation and to check install use the command.

brew help

To list all the packages that you can install with homebrew use the command.

brew search

A long list will be displayed. If you want to count the number of packages available, ‘search’ with ‘word count’ as a list with the command.

brew search | wc -l

To search for a specific package use the command, or the brew web page search engine here.

brew search <name of the package>

Example

brew search postgres

Results can be of two types:
- Formulae which typically deals with command software and,
- Cask is and extension of homebrew that allows us to install macOS native applications like google chrome, etc.

To install packages with brew, first check if the package exist, type the name of the package, ex. tree command.
If the package is not installed the message bash: tree: command not found will be displayed. To install the package (tree) use the command.

brew install tree

To see the path of the installed package (in this case tree), type in terminal.

which <pckg name>   ex.
which tree

Terminal will display /usr/local/bin/tree, which seem to be the path of the folder where the package was saved, but in reality is a symbolic link or symlink.
To see the real location use the commands list and list-out and copy the symlink of the packege.

ls -la /usr/local/bin/tree

Terminal will display lrwxr-xr-x 1 Marcelo-Rosales admin 29 Jan 4 18:04 /usr/local/bin/tree -> ../Cellar/tree/1.8.0/bin/tree, where the last portion ../Cellar/tree/1.8.0/bin/tree indicates the real location of the package.

To see more information of the package, like the description, where and when was installed, etc. use the command.

brew info tree

If not installed it will also show the dependencies need for the installation. ex. brew info node.
To uninstall a package.

brew uninstall tree 

If you want to install GNU packages that are already install natively in and from macOS. It will not over-write over the original, instead it will add a g prefix in the name of the new package.

To see the outdate packages that need an update use the command.

brew outdated

Then brew update and brew upgrade. However; by default, brew does not remove old version of a package. To remove this outdated version run the command.

brew cleanup

To install applications, use the command cask, ex.

brew cask install firefox

Recently the “cask” command has been modify to “–cask”. From now on the command line would be like:

brew install --cask firefox

to see info or go directly to the home web page of the application use.

brew info --cask firefox
brew homepage --cask firefox

To install packages from git repositories, we can tap the repository and then install the package. This packages Formulae or casks are usually not available in the brew search or web. So;
1st.: we have to pull the formulae or casks from the git repository with

brew tap <name of the repository>  

Ex.

brew tap heroku/brew

2nd.: Search in brew if the formulae or cask were saved.This will pull the Formulae needed to install.

brew search heroku

3rd.: If present, then install as normal.

brew install heroku

2.2 Brew Bundle and the “Brewfile”: Tips

In brew Install “mas”, it lets you install and update application from the apple store.

brew list mas || brew install mas

or

brew install mas

Install the command “brew bundle”: With this package you can dump all the programs and applications that you installed with brew over time in a “brew file”. https://twit.tv/shows/hands-on-mac/episodes/9.

brew bundle

or

brew bundle install   

link here

At first install (or if never done before) there is no brewfile and Error: No Brewfile found. To create a brew file run:

brew bundle
brew install bash-completions

To see the # of packages available in brew.

brew search

To see the list of packages, [word count]- list

brew search | wc -l

To search a specific package.

brew search [name of package]
brew search postgres

Homebrew Tutorial video

To install a package:
brew install tree

To see the path where brew saves the packages:
which [name of package]
Ex
which tree

Output answer in console:
/usr/local/bin/tree.

However, this is not the folder, this is just a symbolic link. To see the real location:
ls -la [symbolic path]
Ex. ls -la /usr/local/bin/tree
Output answer in console:
lrwxr-xr-x 1 marcelorosales admin 29 Dec 29 20:36 /usr/local/bin/tree -> ../Cellar/tree/1.8.0/bin/tree
This means that the location is in /usr/local/Cellar directory.

For more info on the package, if is not installed it will show and also will show the dependencies it needs.
brew info tree

To uninstall a package
brew uninstall tree

To see the version of packages:
grep --version

If there is already a native package on the operating system, for instance macOS grep. Then the new package installed will have a “g” prefix.

brew update
brew outdated
Brew upgrade
brew clean up
brew doctor 

To install Mac applications use the “cask” command. Example.

brew cask install firefox 

To open the webpages of the application directly from terminal, use

brew home rstudio
brew home r
brew home pycharm

2.3 Using Scripts to Automate Installs (and save time in Install and setup)

video link
Homebrew must be installed. In homebrew, make sure that git is installed, also, that your Automated scripts are in your repository. To check in Terminal run git.

git

If it displays git commands, then git is install and ready to connect.
>
>


2.5 Linux/Mac Terminal Tutorials: List.

Link to site.

Command Result Example
pwd prompt working directory
mkdir make a directory mkdir TestDir
ls List of files within a Directory
cd To navigate into a Directory cd TestDir/
touch To create a file touch test_file.txt
open To open a file with default program in my machine open test_file.text
cp To make a copy of the file and set a different name cp test_file.txt copy_file.txt
mv To move a file to a different directory mv test_file.txt DirNamePath/
mv mv is also used for renaming files, we are moving the file to the same folder but with a different name. mv test_file.txt newname_file.txt
To move and rename at the same time. Especify DirPath or up one dir with ../ mv test_file.txt _filePath_ NewName_file.txt
rm To delete or remove a file make sure you are in the same directory as the file. !Warning This command will delete file from system without warning and it will not move it to trash! rm test_file.txt
For Directories
mkdir To make a new directory mkdir NewDir
cp Copy a directory. cp TestDir/ NewDir/
man To find more options about the command, use the command manual. To quit press q man cp
cp -R ... copies the director and the entire subtree `cp -R TestDir/ CopyDir/

Not finished…. finish this later.


2.6 Customizing Your Terminal: .bash_profile and .bashrc files

Link to article.

You can modify Terminal temporally. ex. By typing in Terminal.

PS1="Marcelo ->"  

This will change the prompt name to “Marcelo ->”, but this is only temporary, once we quit terminal, those changes are lost.

To customize this preferences permanently we need 2 modify or create 2 dot files located in our home directory.
1. .bash_profile and 2. .bashrc

This files may or maynot exist in the computer, (In my new computer did not exist neither of these files). To find these files, go to your home directory.

pwd # (present working directory). If not at home directory, go to /Users/Marcelo-Rosales.  
ls -la # list files and list attribute files (hidden files) or .  
find .bash_profile # to find the .file.   

To clear prior customization, move or delete 2 bash files.

mk  
mv .bash_profile DotFiles/ # this command will move bash files in to a folder named "DotFiles".  
mv .bashrc DotFiles/ 

The bash_Profile is used for login shell. The bashrc file is used for non login shell. To create a .bash_profile and a .bashrc file. touch .bash_profile touch .bashrc Open with Atom.


2.7 How to Install Windows 10 on a Mac using VirtualBox (2020 Tutorial).

Link to site.