在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):nicolashery/mac-dev-setup开源软件地址(OpenSource Url):https://github.com/nicolashery/mac-dev-setup开源编程语言(OpenSource Language):Shell 100.0%开源软件介绍(OpenSource Introduction):macOS Dev SetupThis document describes how I set up my developer environment on a new MacBook or iMac. We will set up popular programming languages (for example Node (JavaScript), Python, and Ruby). You may not need all of them for your projects, although I recommend having them set up as they always come in handy. The document assumes you are new to Mac, but can also be useful if you are reinstalling a system and need some reminder. The steps below were tested on macOS High Sierra (10.13), but should work for more recent versions as well. Contributing: If you find any mistakes in the steps described below, or if any of the commands are outdated, do let me know! For any other suggestions, please understand if I don't include everything. This guide was originally written for some friends getting started with programming on a Mac, and as a personal reference for myself. I'm trying to keep it simple!
System updateFirst thing you need to do, on any OS actually, is update the system! For that: Apple Icon > About This Mac then Software Update.... System preferencesIf this is a new computer, there are a couple of tweaks I like to make to the System Preferences. Feel free to follow these, or to ignore them, depending on your personal preferences. In Apple Icon > System Preferences:
SecurityI recommend checking that basic security settings are enabled. You will be happy to have done so if ever your Mac is lost or stolen. In Apple Icon > System Preferences:
iTerm2InstallSince we're going to be spending a lot of time in the command-line, let's install a better terminal than the default one. Download and install iTerm2. In Finder, drag and drop the iTerm Application file into the Applications folder. You can now launch iTerm, through the Launchpad for instance. Let's just quickly change some preferences. In iTerm2 > Preferences..., under the tab General, uncheck Confirm closing multiple sessions and Confirm "Quit iTerm2 (Cmd+Q)" command under the section Closing. In the tab Profiles, create a new one with the "+" icon, and rename it to your first name for example. Then, select Other Actions... > Set as Default. Under the section General set Working Directory to be Reuse previous session's directory. Finally, under the section Window, change the size to something better, like Columns: 125 and Rows: 35. When done, hit the red "X" in the upper left (saving is automatic in macOS preference panes). Close the window and open a new one to see the size change. Beautiful terminalSince we spend so much time in the terminal, we should try to make it a more pleasant and colorful place. What follows might seem like a lot of work, but trust me, it'll make the development experience so much better. First let's add some color. There are many great color schemes out there, but if you don't know where to start you can try Atom One Dark. Download the iTerm presets for the theme by running:
Then, in iTerm2 Preferences, under Profiles and Colors, go to Color Presets... > Import..., find and open the Atom One Dark.itermcolors file we just downloaded. Repeat these steps for Atom One Light.itermcolors. Now open Color Presets... again and select Atom One Dark to activate the dark theme (or choose the light them if that's your preference). Not a lot of colors yet. We need to tweak a little bit our Unix user's profile for that. This is done (on macOS and Linux), in the We'll come back to the details of that later, but for now, just download the files .bash_profile, .bash_prompt, .aliases attached to this document into your home directory (
With that, open a new terminal tab (Cmd+T) and see the change! Try the list commands: Now we have a terminal we can work with! (Thanks to Mathias Bynens for his awesome dotfiles.) HomebrewPackage managers make it so much easier to install and update applications (for Operating Systems) or libraries (for programming languages). The most popular one for macOS is Homebrew. InstallAn important dependency before Homebrew can work is the Command Line Developer Tools for Xcode. These include compilers that will allow you to build things from source. You can install them directly from the terminal with:
Once that is done, we can install Homebrew by copy-pasting the installation command from the Homebrew homepage inside the terminal:
Follow the steps on the screen. You will be prompted for your user password so Homebrew can set up the appropriate permissions. Once installation is complete, you can run the following command to make sure everything works:
UsageTo install a package (or Formula in Homebrew vocabulary) simply type:
To see if any of your packages need to be updated:
To update a package:
Homebrew keeps older versions of packages installed, in case you want to rollback. That rarely is necessary, so you can do some cleanup to get rid of those old versions:
To see what you have installed (with their version numbers):
Homebrew ServicesA nice extension to Homebrew is Homebrew Services. It will automatically launch things like databases when your computer starts, so you don't have to do it manually every time. Homebrew Services will automatically install itself the first time you run it, so there is nothing special to do. After installing a service (for example a database), it should automatically add itself to Homebrew Services. If not, you can add it manually with:
Start a service with:
At anytime you can view which services are running with:
GitmacOS comes with a pre-installed version of Git, but we'll install our own through Homebrew to allow easy upgrades and not interfere with the system version. To do so, simply run:
When done, to test that it installed fine you can run:
The output should be Let's set up some basic configuration. Download the .gitconfig file to your home directory:
It will add some color to the Next, we'll define your Git user (should be the same name and email you use for GitHub and Heroku):
They will get added to your On a Mac, it is important to remember to add
Visual Studio CodeWith the terminal, the text editor is a developer's most important tool. Everyone has their preferences, but if you're just getting started and looking for something simple that works, Visual Studio Code is a pretty good option. Go ahead and download it. Open the .dmg file, drag-and-drop in the Applications folder, you know the drill now. Launch the application. Note: At this point I'm going to create a shortcut on the macOS Dock for both for Visual Studio Code and iTerm. To do so, right-click on the running application and select Options > Keep in Dock. Just like the terminal, let's configure our editor a little. Go to Code > Preferences > Settings. In the very top-right of the interface you should see an icon with brackets that appeared { } (on hover, it should say "Open Settings (JSON)"). Click on it, and paste the following: {
"editor.tabSize": 2,
"editor.rulers": [80],
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"workbench.editor.enablePreview": false
} Feel free to tweak these to your preference. When done, save the file and close it. Pasting the above JSON snippet was handy to quickly customize things, but for further setting changes feel free to search in the "Settings" panel that opened first (shortcut Cmd+,). When you're happy with your setup, you can save the JSON to quickly restore it on a new machine. If you remember only one keyboard shortcut in VS Code, it should be Cmd+Shift+P. This opens the Command Palette, from which you can run pretty much anything. Let's open the command palette now, and search for
VS Code is very extensible. To customize it further, open the Extensions tab on the left. Let's do that now to customize the color of our editor. Search for the Atom One Dark Theme extension, select it and click Install. Repeat this for the Atom One Light Theme. Finally, activate the theme by going to Code > Preferences > Color Theme and selecting Atom One Dark (or Atom One Light if that is your preference). VimAlthough VS Code will be our main editor, it is a good idea to learn some very basic usage of Vim. It is a very popular text editor inside the terminal, and is usually pre-installed on any Unix system. For example, when you run a Git commit, it will open Vim to allow you to type the commit message. I suggest you read a tutorial on Vim. Grasping the concept of the two "modes" of the editor, Insert (by pressing Vim's default settings aren't great, and you could spend a lot of time tweaking your configuration (the Using Vim's built-in package support, install these settings by running:
With that, Vim will look a lot better next time you open it! PythonmacOS, like Linux, ships with Python already installed. But you don't want to mess with the system Python (some system tools rely on it, etc.), so we'll install our own version using pyenv. This will also allow us to manage multiple versions of Python (ex: 2.7 and 3) should we need to. Install
When finished, you should see instructions to add something to your profile. Open your if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)"; fi Save the file and reload it with:
Before installing a new Python version, the pyenv wiki recommends having a few dependencies available:
We can now list all available Python versions by running:
Look for the latest 3.x version (or 2.7.x), and install it (replace the
List the Python versions you have locally with:
The star ( You can switch your current terminal to another Python version with:
You should now see that version when running:
In a project directory, you can use:
This will save that project's Python version to a For more information, see the pyenv commands documentation. pippip was also installed by Here are a couple Pip commands to get you started. To install a Python package:
To upgrade a package:
To see what's installed:
To uninstall a package:
virtualenvvirtualenv is a tool that creates an isolated Python environment for each of your projects. For a particular project, instead of installing required packages globally, it is best to install them in an isolated folder, that will be managed by Instead of installing and using
After installation, add the following line to your if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi And reload it with:
Now, let's say you have a project called
See the list of virtualenvs you created with:
To use your project's virtualenv, you need to activate it first (in every terminal where you are working on your project):
If you run Now when you install something:
It will get installed in that virtualenv's folder, and not conflict with other projects. You can also set your project's
Next time you enter that project's directory, Anaconda and MinicondaThe Anaconda/Miniconda distributions of Python come with many useful tools for scientific computing. You can install them using
After loading an Anaconda or Miniconda Python distribution into your shell, you can create conda environments (which are similar to virtualenvs):
Install packages, for example the Jupyter Notebook, using:
You should now be able to run the notebook:
Deactivate the environment, and return to the default Python version with:
Known issue: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论