Mobile robots with artificial intelligence are more and more popular on the rescue and human-service in complex environment. Path planning techniques for robots become the important topic to achieve it. Recently, Q-learning becomes a popular topic since the property of model-free. In this paper, generating the collision-free and optimal path with Q-learning for an mobile robot is proposed. Q-learning is adopted to let the mobile robot achieve the destination successfully through designing the states, actions and reward function in this paper. The system structure is integrated by two parts. First, the Q-learning algorithm is applied to find the collision-free and optimal path for an mobile robot. Second, Robot Operation System (ROS) is used to be the data transmission system among the dynamic path planning system, global position system and mobile robot. In the simulation result, the dynamic path planning system generates the collision-free and optimal path for the mobile robot. In addition, the movable obstacles appear on the original path suddenly, then the dynamic path planning system would regenerate a new optimal path to achieve the goal successfully.