According to Wiktionary, step by step is the adverbial form, whereas step-by-step is the adjectivial. So your second example is the correct one.