Modern CSS with Sass - practical tutorial

Installing Sass: Setting Up Ruby and Sass on Windows

All videos of the tutorial Modern CSS with Sass - practical tutorial
Daniel Koch
By Daniel Koch Last updated on

Anyone who wants to use Sass can't get around the installation. Sass is a CSS preprocessor, and for it to work, you first need Ruby. In this tutorial, you set up both on Windows, check the installation, and convert a simple SCSS file into a CSS file.

Modern CSS with Sass - 02 The installation

The video is only loaded from YouTube when you play it – data (including your IP address) is then transmitted to YouTube/Google. More in the privacy policy

Note upfront: This tutorial is based on Ruby Sass, the original implementation. It was discontinued in 2019. For new projects, Dart Sass is recommended today. However, the basic idea remains the same: you write SCSS and have it translated into CSS.

Key takeaways

  • Sass requires Ruby as a prerequisite. You install Ruby on Windows via the Ruby Installer.
  • You then install Sass with the command gem install sass in the command line.
  • With sass -v you check whether the installation worked by having the version number displayed.
  • You convert an SCSS file into a normal CSS file with sass input.scss output.css.
  • On a Mac, the installation works similarly. You may need administrator rights and therefore have to put sudo in front of the command.

Step 1: Download Ruby and start the installation

Before you can install Sass, you need Ruby. To do so, go to the rubyinstaller.org website and choose the download for Windows. It's best to take the latest version. At around 17.5 MB, the installer is quite small and can therefore be downloaded quickly. Then start the downloaded file, and a wizard opens.

Installing Sass: Setting Up Ruby and Sass on Windows

Step 2: Choose a language and accept the license terms

In the wizard, you select English as the language. The selection also includes options such as Chinese, but that is irrelevant for the installation. Confirm your selection with "OK". Then you accept the license terms and click "Next". The actual installation is a wizard that guides you step by step, and you don't have to make any special settings here.

Installing Sass: Setting up Ruby and Sass on Windows

Step 3: Specify the installation directory

Next, you specify where Ruby should be installed. In the video, the directory C:\Ruby is chosen. This has a practical advantage: when you work via the command line later, you can reach this folder faster with a short path. However, you can also choose a different path, as long as you remember it.

Installing Sass: Setting up Ruby and Sass on Windows

Step 4: Add Ruby to the path

In the installer, you will also find the option to add Ruby to the system path as an executable variable. Be sure to enable this option. This allows Windows to find the ruby command and later also gem and sass from anywhere. Without this setting, you would have to specify the full path every time.

Step 5: Complete the installation

After you have set the options, you start the installation. It usually runs quickly. Once the process is complete, Ruby is available on your system. With that, you have accomplished the prerequisite for Sass.

Step 6: Open the command line

For the next step, you need the command line. With the Ruby installation, you get your own command line included, which you can open via the Start menu. However, you can also use the normal Command Prompt or PowerShell, since the path is now set.

Installing Sass: Setting Up Ruby and Sass on Windows

Step 7: Install Sass with gem

Now comes the actual step. In the command line, change to the directory where Ruby is installed, for example with cd C:\Ruby. Then enter the following command:

gem install sass

The gem command is Ruby's package manager, and sass is the name of the package you want to install. Confirm the input with the Enter key. The connection to the package server is established, and this may take a short moment. So don't be surprised if nothing happens at first. Once the download is running, it usually goes very quickly.

Installing Sass: Setting up Ruby and Sass on Windows

Step 8: Test the installation with the version number

The easiest way to test whether Sass was installed correctly is via the version number. To do this, enter the command sass -v in the command line and confirm it. If Sass is installed, a version number appears; in the video, 3.4.22 is displayed here. If an error message appears instead, either you did not install Sass correctly or Ruby is not added to the path. In this case, you should check Step 4 again.

Step 9: Create a working directory and an SCSS file

Now we want to try out the installation in practice. To do this, create a new directory in which you will store your files. In the video, this folder is called "tutkit". In this directory, you then create a new file with the extension .scss. The name can be chosen freely; in the video, the file is called fong.scss. What matters is that the extension is .scss, because that is how Sass recognizes that it is a Sass file.

Installing Sass: Setting Up Ruby and Sass on Windows

Step 10: Write simple code into the file

Open the SCSS file with an editor of your choice. Now write a simple CSS example into it, for instance a rule for the outer spacing, which you set with margin: 0.5em;. For this test, you do not yet need to use any special Sass features. For now, it is only about making sure the conversion works. The special features of SCSS, such as variables or nesting, are covered by the guide in later parts.

Installing Sass: Setting Up Ruby and Sass on Windows

Step 11: Convert the SCSS file to CSS

Now you convert the file. In the command line, switch to your working directory, which in the video is done with cd tutkit. Then you enter the basic command:

sass fong.scss fong.css

After sass comes the input file, that is, the SCSS file, followed by the output file, that is, the CSS file that is to be generated. After confirming, no message appears at first. This is normal, because Sass works silently in the background.

Installing Sass: Setting Up Ruby and Sass on Windows

Step 12: Check the result

Now look in the directory to see whether the file fong.css was created. Then open it. You will see pure CSS, that is, the normal syntax that you already know. What may stand out are the changed indentation and a reference to a map file. This map file helps developer tools such as those in Google Chrome or Firefox to link the lines of the CSS file back to the lines of the SCSS file. To begin with, you do not need to understand it, but you should not delete it out of curiosity before you know what it is for.

Installing Sass: Setting Up Ruby and Sass on Windows
Installing Sass: Setting Up Ruby and Sass on Windows

Summary – Installing Sass on Windows: Ruby, gem and the first conversion

You have seen that the installation consists of two parts. First, you install Ruby via the Ruby Installer and enable the option for the path. Then you install Sass with gem install sass and check for success with sass -v. Afterwards, you create an SCSS file and convert it to CSS with sass eingabe.scss ausgabe.css. The effort is manageable, and with this foundation you can try out the actual possibilities of Sass in the next steps.

FAQ

Do I absolutely need Ruby to use Sass?Yes, Ruby Sass requires Ruby as a prerequisite. Installing Sass via gem therefore necessarily requires that Ruby was installed beforehand.

What do I do if sass -v does not work?First check whether Ruby is added to the system path. If the option was not enabled during installation, the command will not work. Then restart the command line so that the change takes effect.

Do I have to do anything differently on a Mac?The steps are similar. However, make sure you have the necessary user permissions. If you install via the command line, you often put sudo in front of the command.

Can I also name the file fong.scss something else?Yes, you can choose the name freely. It is only important that the extension is .scss so that Sass recognizes the file.

What does the map file that is created during conversion mean?The map file links the generated CSS file to the original SCSS file. Developer tools in the browser can thereby directly display the SCSS lines, which makes troubleshooting easier.

Daniel Koch
Trainer About Daniel Koch Daniel Koch has been at home in web development since 1998. After a classic start with HTML, JavaScript and dynamic languages such as php quickly followed. All courses by Daniel Koch