Homebrew is a great way to install and manage open source development tools on your Mac from the command line. Install Homebrew and run the following to install an up to date version of Git on your Mac: brew install git. To update your Git install, use Homebrew's upgrade option: brew upgrade git. Install GitLab Runner on macOS. GitLab Runner can be installed and updated on macOS. There are two methods for installing GitLab Runner on macOS: Manual installation. This method is officially supported and recommended by GitLab. Homebrew installation. Install with Homebrew as an alternative to manual installation.
Historically MacOS came preinstalled with Python 2, however starting with Mac 10.15 (released in October 2019) this is no longer the case. And since Python 2 will no longer be officially supported as of January 1, 2020, you should really use Python 3 instead.
There are multiple ways to install Python 3 on a MacOS computer. The official Python website even recommends downloading it directly, however this approach can cause confusion around PATH variables, updates, and uninstalls. A better approach, in my opinion, is to instead use the popular package manager Homebrew which automates updates and juggling multiple versions of Python on a computer.
Is Python 3 already installed?
Before we start, make sure Python 3 isn't already installed on your computer. Open up the command line via the Terminal application which is located at Applications -> Utilities -> Terminal
.
Then type the command python --version
followed by the Enter key to see the currently installed version of Python.
Note: The dollar sign, ($
), indicates user input. Everything after is intended to be typed by the user followed by the Enter key. Any output, such as Python 2.7.17
in this case, does not have a dollar sign in front.In short: don't type $
before your commands!
It's possible that Python 3 may have already been installed as python3
. Run the command python3 --version
to check, however most likely this will throw an error.
Install XCode
The first step for Python 3 is to install Apple's Xcode program which is necessary for iOS development as well as most programming tasks. We will use XCode to install Homebrew.
In your Terminal app, run the following command to install XCode and its command-line tools:
It is a large program so this make take a while to download. Make sure to click through all the confirmation prompts XCode requires.
Install Homebrew
Next install Homebrew by copy/pasting the following command into Terminal and then type Enter:
To confirm Homebrew installed correctly, run this command:
Install Python 3
Now we can install the latest version of Python 3. Type the following command into Terminal and press Enter:
To confirm which version of Python 3 was installed, run the following command in Terminal:
Finally, to run our new version of Python 3 open an interactive shall by typing python3
within Terminal:
To exit the Python 3 interactive shell, you can type either exit()
and then Return or type Control+d
which means hold both the Control and D keys at the same time.
Note that it is still possible to run Python 2 by simply typing python
:
Virtual Environments
By default, Python packages are installed globally on your computer in a single directory. This can cause major problems when working on multiple Python projects!
For example, imagine you have Project A that relies upon Django 1.11 whereas Project B uses Django 2.2. If you naively installed Django on your computer, only the latest install would be present and available in that single directory. Then consider that most Python projects rely on multiple packages that each have their own version numbers. There's simply no way to keep everything straight and not inadvertently break things with the wrong package versions.
The solution is to use a virtual environment for each project, an isolated directory, rather than installing Python packages globally.
Confusingly, there are multiple tools for virtual environments in Python:
- venv is available by default on Python 3.3+
- virtualenv must be installed separately but supports Python 2.7+ and Python 3.3+
- Pipenv is a higher-level tool that automatically manages a separate virtual environment for each project
On MacOS we can install Pipenv with Homebrew.
Then use Pipenv for any Python packages you wish to install. For example, if you want to work with Django 2.2.6, first create a dedicated directory for it on your computer such as in a django
directory on your Desktop.
Then install Django within that directory.
If you look within the directory there are now two new files, Pipfile
and Pipfile.lock
, which Pipenv uses. To activate the virtual environment type pipenv shell
.
There will now be parentheses around the name of your current directory which indicates the virtual environment is activate. To exit the virtual environment, type exit
.
The lack of parentheses confirms the virtual environment is no longer active.
Next Steps
To learn more about Python, the books Python Crash Course and Automate the Boring Stuff are great resources. For free tutorials on web development with Python check out Learn Django.
-->By: Robert Outlaw
Git isn't usually set up by default on your computer, so you need toinstall and configure it before you can start using it to manage yourcode. It's important to keep Git up to date, just like all the othersoftware on your machine. Updates protect you from securityvulnerabilities, fix bugs, and give you access to new features.
The recommended method of installing and maintaining Git is provided forthree major platforms below.
Windows
Download and install Git for Windows. Once installed, you'll beable to use Git from the command prompt or PowerShell. We recommend thatyou stick with the defaults selected during the installation unless youhave a good reason to change them.
Git for Windows does not automatically update. Update Git for Windows bydownloading a new version of the installer, which will update Git forWindows in place and keep all of your settings.
macOS
macOS 10.9 (Mavericks) or higher will install Git the first time you tryto run Git from the Terminal. This is an easy way to get Git on yoursystem, but you can't control exactly how often you get updates orsecurity fixes for Git.
We recommend installing Git through Homebrew andusing the Homebrew tools to keep Git up to date. Homebrew is a great wayto install and manage open source development tools on your Mac from thecommand line.
Install Homebrew and run the following to install anup to date version of Git on your Mac:
> brew install git
Install Homebrew Mac Terminal Command
Finally, to run our new version of Python 3 open an interactive shall by typing python3
within Terminal:
To exit the Python 3 interactive shell, you can type either exit()
and then Return or type Control+d
which means hold both the Control and D keys at the same time.
Note that it is still possible to run Python 2 by simply typing python
:
Virtual Environments
By default, Python packages are installed globally on your computer in a single directory. This can cause major problems when working on multiple Python projects!
For example, imagine you have Project A that relies upon Django 1.11 whereas Project B uses Django 2.2. If you naively installed Django on your computer, only the latest install would be present and available in that single directory. Then consider that most Python projects rely on multiple packages that each have their own version numbers. There's simply no way to keep everything straight and not inadvertently break things with the wrong package versions.
The solution is to use a virtual environment for each project, an isolated directory, rather than installing Python packages globally.
Confusingly, there are multiple tools for virtual environments in Python:
- venv is available by default on Python 3.3+
- virtualenv must be installed separately but supports Python 2.7+ and Python 3.3+
- Pipenv is a higher-level tool that automatically manages a separate virtual environment for each project
On MacOS we can install Pipenv with Homebrew.
Then use Pipenv for any Python packages you wish to install. For example, if you want to work with Django 2.2.6, first create a dedicated directory for it on your computer such as in a django
directory on your Desktop.
Then install Django within that directory.
If you look within the directory there are now two new files, Pipfile
and Pipfile.lock
, which Pipenv uses. To activate the virtual environment type pipenv shell
.
There will now be parentheses around the name of your current directory which indicates the virtual environment is activate. To exit the virtual environment, type exit
.
The lack of parentheses confirms the virtual environment is no longer active.
Next Steps
To learn more about Python, the books Python Crash Course and Automate the Boring Stuff are great resources. For free tutorials on web development with Python check out Learn Django.
-->By: Robert Outlaw
Git isn't usually set up by default on your computer, so you need toinstall and configure it before you can start using it to manage yourcode. It's important to keep Git up to date, just like all the othersoftware on your machine. Updates protect you from securityvulnerabilities, fix bugs, and give you access to new features.
The recommended method of installing and maintaining Git is provided forthree major platforms below.
Windows
Download and install Git for Windows. Once installed, you'll beable to use Git from the command prompt or PowerShell. We recommend thatyou stick with the defaults selected during the installation unless youhave a good reason to change them.
Git for Windows does not automatically update. Update Git for Windows bydownloading a new version of the installer, which will update Git forWindows in place and keep all of your settings.
macOS
macOS 10.9 (Mavericks) or higher will install Git the first time you tryto run Git from the Terminal. This is an easy way to get Git on yoursystem, but you can't control exactly how often you get updates orsecurity fixes for Git.
We recommend installing Git through Homebrew andusing the Homebrew tools to keep Git up to date. Homebrew is a great wayto install and manage open source development tools on your Mac from thecommand line.
Install Homebrew and run the following to install anup to date version of Git on your Mac:
> brew install git
Install Homebrew Mac Terminal Command
To update your Git install, use Homebrew's upgrade option:
> brew upgrade git
A graphical installer for Git on macOS is also available from theofficial Git website.
Linux
Use your Linux distribution's package management system to install andupdate Git. For example, on Ubuntu:
> sudo apt-get install git
Configure Git
Set up your name and email address before starting to work with Git onyour computer. Git attaches this information to your changes and letsothers identify which changes are yours.
Run the following commands from the command prompt after installing Gitto configure this information:
> git config --global user.name 'Jamal Hartnett'
> git config --global user.email 'jamal@fabrikam.com'
Visual Studio offers a great out of the box Git experience without anyadditional tooling. Learn more in our Visual Studio Git tutorial.
Get started with unlimited free private Git repos in Azure Repos.
Install Homebrew Mac Terminal Tool
Robert is a content developer at Microsoft working on Azure DevOps and Team Foundation Server. |