Just the idea of retiring someday can feel daunting when you earn a pretty average salary. But retiring with a couple of million dollars? That seems downright impossible.

Yet with enough time and patience, it's entirely possible, even if you didn't start investing in your early 20s. Here are four steps to retiring with $2 million if you have a $60,000 salary.

A senior couple drinks Champagne in a limousine.

Image source: Getty Images.

1. Prioritize jobs with a 401(k) match

Salary is probably your biggest concern when you're looking for a job, but finding a job at a company that offers a 401(k) match should be a high priority as well. To get to $2 million, you'd need to invest about $600 a month over 35 years, assuming 10% annual returns. That's 12% of a $60,000 salary before taxes.

But if you find a job that offers a fairly typical 401(k) match of 50% of your contributions up to 6%, your employer would be kicking in $150 a month, so you'd only need to invest $450 each month. Or you could aim to contribute $600 out of your own pocket and take advantage of your company match, meaning you'd invest $750 a month. You could retire about two and a half years earlier and still have $2 million.

Bonus points if you have a health savings account (HSA). You can use the money in the account for any reason without penalty once you reach 65, though you'll still owe income taxes.

2. Build an emergency fund

One of the biggest threats to your future millionaire status is a poorly timed emergency. If you have to withdraw retirement funds early when the market is down, you'll not only lose money, but you'll also typically owe taxes and a 10% penalty.

To avoid an early retirement withdrawal, building a six-month emergency fund is vital. You can start small by aiming for three months' savings. Then contribute enough to your 401(k) to get your employer's full match while putting any extra money in your emergency fund until you have six months of expenses saved. 

It's essential to keep your emergency fund out of the stock market so that it isn't subject to fluctuations. Keep it in a bank account so you can easily access it in your time of need.

3. Invest across the stock market

Investing in S&P 500 index funds has been a winning bet for patient investors. The S&P 500 index tracks the stock performance of 500 of the largest domestic corporations, representing more than 80% of the U.S. stock market by market capitalization. Rather than trying to beat the stock market, an S&P 500 fund tries to replicate its performance.

Simply mirroring the stock market's performance is a great way to get rich slowly because the S&P 500 index has delivered annual returns of 9% to 10% historically. In fact, famed investor Warren Buffett has often said that investing in low-cost S&P 500 funds is the best way for most people to build wealth.

4. Be consistent

Let's face it: Investing $600 a month on a $60,000 salary over 30 to 35 years takes a lot of discipline. It also requires you to stay invested, even when the market just crashed and you want to panic and cash out. But most successful investors don't bother trying to time the market because they know they can't predict its short-term performance.

Instead, they practice dollar-cost averaging, which means they invest a certain amount on a schedule whether the market is up or down. If you contribute to a 401(k), you're probably already doing this because you typically invest by automatically deferring part of your paycheck.

This habit tends to maximize investment returns in the long run. It prevents you from only investing when the market is strong and stocks are at a premium, even though it may not produce the best short-term results. But when your goal is to become a millionaire in retirement, long-term performance is the only thing that matters.