Do you need to build both? Maybe. It depends. I'd say that if there is a 1:1 mapping between classes in a UML Class Diagram and components in a UML Component Diagram, you probably don't need both diagrams.
The intention of both diagrams is different, though. Class diagrams specifically show classes (and modules or packages), along with their attributes, methods, and relationships. You can get into the details of interfaces and abstract classes and visibility (public, private, protected) of attributes and methods, aggregation and composition, and so on. Of course, the level of detail in a class diagram depends on the audience. Component diagrams are a higher level of abstraction. A component could be something more like a module, an API, a service, an application, a database. If you are building in an object-oriented language, I would suspect that a component would be a set of classes, perhaps a deployable unit.
If you find yourself changing a Component Diagram every time you make a change to a Class Diagram, your Component Diagram is probably at too low of a level of abstraction. I'd think harder about what a "component" is and if it makes sense to use the Component Diagram for your system.