www.example.com and example.com are two separate DNS names, for two separate servers. If you want the two names to resolve to the same host, you’ll need to have DNS translations for both names, and the www host will need to be redirected to not-www host.
Most registrars will have a subdomain creation facility somewhere in their DNS configuration portal.
Once you have the www subdomain created, you can then set up the desired forwarding.
Here is how to redirect a www.example.com virtual host on port 80 HTTP to the preferred example.com:80 host, assuming the Apache web server.
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / http://example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
# real server configuration
</VirtualHost>
If you don’t want to bother with that, you can also configure www.example.com and example.com to resolve to the same server, though you will still need to set up a virtual host for both names there, if you are using something like a web server with virtual hosting capabilities; with Apache, nginx, or otherwise.