Installing Xcode command line tools
Check the version of your operating system. If your version number is 10.9 or
higher, follow the next step. If your OS X version is less than 10.9, you should
consider upgrading your operating system to 10.9 or higher. It's completely
free.
In this book, we will not be installing Xcode. Hence no need to download Xcode
from App Store. In this section, we will be installing Xcode command line
developer tools.
We can install Xcode command line developer tools like this:
Dotfiles and setting up your Mac
We recommend that you follow the README
and setup your dotfiles accordingly.
Installing Node.js
Different applications use different versions of Node.js.
Thus it is useful to be able to switch between different versions of Node.js on
the fly.
We recommend Node Version Manager (nvm),
which helps us maintain the correct Node.js version specific to a project, and
switch between them without much hassle.
Running the below command on your terminal will install nvm locally.
Installing a Node.js version using nvm
Currently, we use Node.js v22.13 in our wheel project. You can install the
same version by running the following:
If you're not a fan of nvm, then n is a good
alternative.
Installing Yarn
You shouldn't use npm command in BigBinary projects.
We make use of yarn to manage JavaScript libraries and tool chains.
Install it:
Setting up VSCode
VSCode, short for Visual Studio Code, can be downloaded and installed from
their official website.
If you're using M1 Mac, then you can opt for Apple Silicon build and download
it from their website.
These are the steps for installation:
- Download Visual Studio Code for macOS.
- Open the browser's download list and locate the downloaded archive.
- Select the 'magnifying glass' icon to open the archive in Finder.
- Drag
Visual Studio Code.app to the Applications folder, making it
available in the macOS Launchpad.
- Add VSCode to your Dock by right-clicking on the icon to bring up the context
menu and choosing
Options > Keep in Dock.
Most of us in BigBinary use VSCode as our daily tool for editing files. Thus if
you ever wanted to check out how to do something faster or better in VSCode,
then your colleagues are always there to help you out!
Enabling code command
To run VSCode from terminal, we need to add code command in to our PATH.
Run the following command from your terminal:
Since we have made changes to .zshrc we need to reload the shell for the
changes to take effect. The easiest way to do so is to quit the current terminal
and open a new terminal.
Now let's test if command code is working or not.
Open terminal and type code dummy.txt and that file should be opening up in
VSCode.
Enabling auto save feature
Auto Save feature will save your changes after a configured delay or when
focus leaves the editor.
With this option turned on, there is no need to explicitly save the file.
The easiest way to turn on Auto Save is with the File > Auto Save toggle from
menu bar, that turns on and off save option after a delay.
Other way of enabling this feature, is by appending the following to your user
settings and reload. It does the same job:
Here are some optional settings you can set to VSCode globally. You can press Cmd + Shift + P and input >Preferences: Open User Settings (JSON) to open settings.json file.
Add these lines in the file as settings:
Spell checking in VSCode
If you are using VSCode to write blogs, articles, or generically any markdown
file, etc, then spell checking is very important. To get real time spell
checking on whatever you are editing and to provide automated corrections we use
the
Code Spell Checker
extension from VSCode which we have installed in the last section.
Installing Prettier plugin
To make code more readable and consistent we can install the Prettier plugin.
This tool works well with Visual Studio Code such that code is automatically
formatted every time changes are saved.
Installing the Prettier Visual Studio Code plugin
- Hit Cmd+Shift+P on Mac or Ctrl+Shift+P on Linux.
- Select "Extensions: Install Extensions".
- Search for
Prettier plugin.
- Click "Install" and then reload VSCode after the installation.
Run Prettier every time a JavaScript file is saved
This is also an optional step.
- Hit Cmd+Shift+P on Mac or Ctrl+Shift+P on Linux.
- Type "Preferences: Open Workspace Settings".
- We will see two options.
- Select the option that has the word JSON.
- Paste the following content in the Settings file.
Install system packages
Ruby needs certain system packages like Openssl for it to be compiled properly.
Thus install the following packages from the Rosetta enabled terminal:
Install rbenv
Install rbenv. Using rbenv we can install a
specific version of Ruby:
If you don't know which shell you are using then
refer to this answer.
If you are using zsh shell then use the following command:
If you are using bash shell then execute the following command:
Now restart the terminal and run the following:
Add ~/.rbenv/bin to your $PATH for accessing the rbenv command-line
utility.
If you are using bash shell then execute the following command:
If you are using zsh shell then use the following command:
Restart the terminal and rbenv should be available as a command.
It's often seen that folks have a Ruby version conflicts in their system. It's
mostly because Ruby gets installed by default on the system level. But
system-level ruby command has different permissions and paths, compared to the
ruby command installed via rbenv.
Thus let's set the global version of the ruby command to be a rbenv specific
version, like this:
Now that we have set the global Ruby version to be an rbenv specific version,
let's verify the same, by running the following commands:
In M1 Mac, we need to install the shared mime info, if it doesn't already exist:
Installing Ruby on Rails on macOS
Now install Ruby on Rails gem:
Flag --no-document disables document generation.
Now install bundler which help us manage Ruby gems:
TypeError for Rails project in M1 Mac
If you ever receive the TypeError: Unable to resolve type 'size_t' error while
working on a Rails project in M1 Mac, then run the following command to fix it:
Rbenv Ruby build definitions not found error
Rbenv Ruby build definitions not found error is thrown if ruby-build is not
installed. ruby-build is an rbenv plugin that provides the rbenv install
command to compile and install different versions of Ruby on UNIX-like systems.
You can check if ruby-build is installed system-wide under homebrew using
which command like this:
If ruby-build already installed, then the following installed path should show
up in the terminal:
Otherwise you will receive the following error:
If ruby-build is not installed, then you should install it like this:
You're now ready to start building with Ruby on Rails on your Mac.