We present an algorithm to calculate the linear response of periodic systems in the time-dependent density functional thoery, using a real-space representation of the electron wave functions and calculating the dynamics in real time. The real-space formulation increases the efficiency for calculating the interaction, and the real-time treatment decreases storage requirements and the allows the entire frequency-dependent response to be calculated at once. We give as examples the dielectric functions of a simple metal, lithium, and an elemental insulator, diamond.