Laptop is a script that will set up a complete Ruby web development environment on your Mac. It also automatically installs the Jekyll and Rails gems.
It can be run multiple times on the same machine safely. It installs, upgrades, or skips packages based on what is already installed on the machine.
You can also easily customize the script to install additional tools.
- Join the 1200+ people on my list who are becoming confident coders through my weekly coding guides and exclusive tutorials and courses.
- For a more minimal script that only installs Ruby (with chruby and ruby-install), check out my install-ruby-on-macos script.
Supported chips:
- Apple Silicon M1
- Intel
Supported operating systems:
- Big Sur
- macOS Catalina
- macOS Mojave
Unsupported operating systems. Give it a shot, but I can't guarantee it will work.
- macOS High Sierra (10.13)
- macOS Sierra (10.12)
- OS X El Capitan (10.11)
- OS X Yosemite (10.10)
- OS X Mavericks (10.9)
Supported shells:
- bash
- zsh
- fish (see the note at the bottom of this README)
IMPORTANT! CHECK ALL OF THE ITEMS BELOW BEFORE RUNNING THE SCRIPT!
Before you run the script, make sure you have the latest Apple software updates installed. Check by going to System Preferences, then Software Update. If you're on Catalina, you don't have to upgrade to Big Sur, just make sure you have the latest Catalina updates.
My script is not compatible with RVM and rbenv. You need to uninstall them first.
rvm implode
Then delete any lines related to RVM from these files if they exist:
~/.bash_profile
~/.zshrc
~/.zprofile
Follow the instructions here: https://github.com/rbenv/rbenv#uninstalling-rbenv Then delete any lines related to rbenv from these files if they exist:
~/.bash_profile
~/.zshrc
~/.zprofile
If you already had Homebrew and/or the command line tools (or Xcode) installed,
you'll need to make sure Homebrew is in a clean state before running my script. Running brew doctor
should return Your system is ready to brew.
. If not, try to fix as many of the problems as you can. Homebrew usually has great instructions for fixing problems.
If you can't solve the Homebrew problems on your own, I can help you if you run my script anyways, then open an issue and attach the laptop.log
file that gets saved in your Home folder.
The Homebrew issue that is the most likely to cause problems is outdated command line tools, which is documented in the troubleshooting Wiki in this repo. It will say something like this when you run brew doctor
:
Warning: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or run:
softwareupdate --all --install --force
If that doesn't show you any updates, run:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Alternatively, manually download them from:
https://developer.apple.com/download/more/.
To fix this, you'll need to remove and reinstall the CLT.
Homebrew works natively on M1 Macs. Make sure to open the default Terminal application, or iTerm, or whatever app you use. Make sure it is not in Rosetta mode.
I mention this several times in this README, as well as when the script finishes successfully, but I'll say it again. For the changes to take effect, you have to "refresh" your terminal. The best way is to quit and relaunch it.
Begin by opening the Terminal application on your Mac. The easiest way to open
an application in macOS is to search for it via Spotlight. The default
keyboard shortcut for invoking Spotlight is command-Space
. Once Spotlight
is up, just start typing the first few letters of the app you are looking for,
and once it appears, press return
to launch it.
In your Terminal window, copy and paste the command below, then press return
.
bash <(curl -s https://raw.githubusercontent.com/monfresh/laptop/master/laptop)
The script itself is available in this repo for you to review if you want to see what it does and how it works.
Note that the script might ask you to enter your macOS password at various
points. This is the same password that you use to log in to your Mac. The
prompt comes from Homebrew, because it needs permissions to write to the
/usr/local
(or /opt/homebrew
on M1 Macs) directory.
If you
have rbenv
or RVM
installed, the script will ask you to uninstall them first
and run the script again. Look at the script output for uninstallation
instructions.
Once the script is done, quit and relaunch Terminal.
I recommend running the script regularly to keep your computer up
to date. Once the script has been installed, you'll be able to run it at your
convenience by typing laptop
and pressing return
in your Terminal.
Your last laptop
run will be saved to a file called laptop.log
in your home
folder. Read through it to see if you can debug the issue yourself, with the help of the Troubleshooting Errors Wiki article. If not,
copy the entire contents of laptop.log
into a
new GitHub Issue (or attach the whole log file to the issue) for me and I'll be glad to help you. If the script doesn't work for you, it's most likely a bug in my script, which I'd love to fix, so please don't hesitate to report any issues.
If the last thing the script displayed was "All done!", then everything the script was meant to do worked.
To verify that the Ruby environment is properly configured, quit and restart Terminal, then run these commands:
ruby -v
This should show ruby 2.7.2
or ruby 3.0.0
. If not, try switching manually to 2.7.2:
chruby 2.7.2
and check the version to double check:
ruby -v
Then check where Ruby is installed:
which ruby
This should point to the .rubies
directory in your home folder. For example:
/Users/monfresh/.rubies/ruby-2.7.2/bin/ruby
Once you've installed the script successfully and restarted your terminal, creating a new Rails app takes just 3 more steps.
Similarly to Rails, creating a new Jekyll site is just as easy.
The first time you run the script (assuming you didn't already have chruby
installed), it will install Ruby 2.7.2, which is the version that is compatible with most gems at the moment. If you run the script again, it will check for newer versions, and it will install Ruby 3.0.0, which was released on December 25, 2020. You will still have Ruby 2.7.2. That's the advantage of using version managers like chruby
. You can have many different versions installed at the same time and you can switch between them.
Ruby 3.0 is still very new, so it's not yet fully compatible with gems like Rails or Jekyll. So, before you create a new Rails app or Jekyll site, make sure you're using Ruby 2.7.2. Keep reading for instructions.
To check if you have Ruby 2.7.2 installed, run this command:
find "$HOME/.rubies" -maxdepth 1 -name 'ruby-2.7.2'
If nothing is returned, then you should install it:
ruby-install ruby-2.7.2
To switch to this newly-installed version, run chruby
followed by the version. For example:
chruby 2.7.2
You should run chruby 2.7.2
before you start any new project to make sure you are using the correct version of Ruby.
Another highly-recommended way to automatically switch between versions is to add a .ruby-version
file in your Ruby project with the version number prefixed with ruby-
, such as ruby-2.7.2
. To test that this works:
cd
into your Ruby project, such as your Rails app or Jekyll site- First, check to see if the file already exists:
cat .ruby-version
. If not, then create it in the next step. - Create a file called
.ruby-version
withruby-2.7.2
in it:echo 'ruby-2.7.2' >> .ruby-version
cd
into a folder outside of your project, such as your home folder:cd ~
- Run
ruby -v
. It will probably say2.6.3p62
, which is the Ruby that came preinstalled on your Mac. cd
into your project- Verify that
ruby -v
shows2.7.2p137
Note that gems only get installed in a specific version of Ruby at a time. If you installed jekyll in 3.0.0, and then you install 2.7.2 later, you'll have to install jekyll again in 2.7.2.
To verify if Node was installed and configured:
node --version
You should see v14.15.3
or later
nodenv help
You should see various commands you can run with nodenv
.
The next thing you'll want to do after running the script is to configure Git with your name, email, and preferred editor.
This script used RVM
at first, but it started causing problems, so I switched to
chruby
, and haven't had any issues since. chruby
is also is the simplest, most
reliable, and easiest to understand. I like that it does not do some of the things
that other Ruby managers do:
- Does not hook
cd
. - Does not install executable shims.
- Does not require Rubies to be installed into your home directory.
- Does not automatically switch Rubies by default.
- Does not require write-access to the Ruby directory in order to install gems.
Other folks who prefer chruby
:
- https://kgrz.io/programmers-guide-to-choosing-ruby-version-manager.html
- https://stevemarshall.com/journal/why-i-use-chruby/
- https://linhmtran168.github.io/blog/2014/02/27/moving-from-rbenv-to-chruby/
- Bundler for managing Ruby gems
- chruby for managing Ruby versions (recommended over RVM and rbenv)
- GitHub CLI brings GitHub to your terminal.
- Heroku Toolbelt for deploying and managing Heroku apps
- Homebrew for managing operating system libraries
- Homebrew Cask for quickly installing Mac apps from the command line
- Homebrew Services so you can easily stop, start, and restart services
- Jekyll for creating static sites
- Nodenv to easily install and manage Node versions
- Rails for creating modern web apps
- Postgres for storing relational data
- ruby-install for installing different versions of Ruby
- Yarn to manage JS dependencies
It should take less than 15 minutes to install (depends on your machine and internet connection).
# Go to your macOS user's root directory
cd ~
# Download the sample files to your computer
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/.laptop.local
curl --remote-name https://raw.githubusercontent.com/monfresh/laptop/master/Brewfile.local
# open the files in your text editor
open .laptop.local
open Brewfile.local
Your ~/.laptop.local
is run at the end of the mac
script.
Put your customizations there. If you want to install additional
tools or Mac apps with Homebrew, add them to your ~/Brewfile.local
.
You can use the .laptop.local
and Brewfile.local
you downloaded
above to get started. It lets you install the following tools and Mac apps:
- Firefox for testing your Rails app on a browser other than Chrome or Safari
- Flux for adjusting your Mac's display color so you can sleep better
- GitHub Desktop for working with your repos using a GUI
- iTerm2 - an awesome replacement for the macOS Terminal
- Nova - Panic's new macOS native code editor
- Redis for storing key-value data
- Sublime Text 3 - a solid and fast code editor
- Visual Studio Code - Microsoft's popular code editor
Write your customizations such that they can be run safely more than once.
See the mac
script for examples.
Laptop functions such as fancy_echo
, and gem_install_or_update
can be used
in your ~/.laptop.local
.
If you want to skip running .laptop.local
, you can set the SKIP_LOCAL
environment variable to true
before running laptop
:
export SKIP_LOCAL=true
laptop
The script does not automatically launch these services after installation because you might not need or want them to be running. With Homebrew Services, starting, stopping, or restarting these services is as easy as:
brew services start|stop|restart [name of service]
For example:
brew services start postgresql
To see a list of all installed services:
brew services list
To start all services at once:
brew services start --all
chruby
does not support the fish shell out of the box. There is a chruby-fish
tool, but it has bugs that manipulate the PATH
in a way it shouldn't. This can prevent using Nodenv if Node is already installed with Homebrew. This is just one example of issues you might run into and not understand why things aren't working. Until the issues are fixed, here is a workaround you can use:
- Uninstall chruby-fish if you have it:
brew uninstall chruby-fish
- Clone this fork of
chruby-fish
to your computer:git clone https://github.com/bouk/chruby-fish/tree/rewrite-fish
- Check out the
rewrite-fish
branch:cd chruby-fish git checkout -b rewrite-fish origin/rewrite-fish
- Run
make install
- Remove any lines from your fish config file that
source
chruby, such as:source /usr/local/share/chruby/chruby.fish source /usr/local/share/chruby/auto.fish source /usr/local/share/chruby/chruby.sh source /usr/local/share/chruby/auto.sh
- Quit and restart Terminal
See this pull request for more information: JeanMertz/chruby-fish#39
This laptop script is inspired by thoughbot's laptop script.
thoughtbot's original work remains covered under an MIT License.
My work on this project is in the worldwide public domain, as are contributions to my project. As stated in CONTRIBUTING:
This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.
All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.