Target-date funds, which are common in many retirement, adjust your investment mix based on your planned retirement date. Many are named for the targeted retirement date, i.e., the 2035 fund or 2040 fund.
You can also use a robo-advisor to allow algorithms to select your investments. Most of the best robo-advisors offer periodic rebalancing, which allows you to shift toward safer investments over time.
Finally, you could also hire a financial advisor to craft a personalized investment strategy. This may not be necessary when you're just starting to invest. But as you move closer to retirement, doing so may be worthwhile to ensure you're on track to hit your goals.