The generalized Langevin equation (GLE) has been recently suggested to simulate the time evolution of classical solid and molecular systems when considering general nonequilibrium processes. In this approach, a part of the whole system (an open system), which interacts and exchanges energy with its dissipative environment, is studied. Because the GLE is derived by projecting out exactly the harmonic environment, the coupling to it is realistic, while the equations of motion are non-Markovian. Although the GLE formalism has already found promising applications, e.g., in nanotribology and as a powerful thermostat for equilibration in classical molecular dynamics simulations, efficient algorithms to solve the GLE for realistic memory kernels are highly nontrivial, especially if the memory kernels decay nonexponentially. This is due to the fact that one has to generate a colored noise and take account of the memory effects in a consistent manner. In this paper, we present a simple, yet efficient, algorithm for solving the GLE for practical memory kernels and we demonstrate its capability for the exactly solvable case of a harmonic oscillator coupled to a Debye bath.