How to Redirect Preferred domain name (www or non-www)

How to redirect website domain name as www to non-www or non-www to www. If it’s hurt Google SEO.
Please provide simply way to do this.

non-www domains not hurt your website SEO. Because world most famous news blog Mashable running under non www domain. . But google take www and non-www domain as different domain. But its not important for SEO. If you feel www is not suitable or compatible for your website or blog change non www to www.

If you want to change your Preferred domain open your website hosting folder.
open .htaccess file.
add the following line to change domain: www to non-www

<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

add the following line to change domain: non – www to www

<IfModule mod_rewrite.c>
    RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Note: remove example and .com instead of your domain name.

Please refer Google guide for Preferred domain.

Changing www or non www domain name can affect Social sharing’s ( Google Plus, Facebook like, Twitter tweets etc) ?

Yes its affect Google plus sharing and twitter tweets. But it not affect Facebook like or recommendations.

If you are using nginx, then use this code to redirect
non-www to www

server {
	listen	   80;
	if ($http_host = {
		rewrite  (.*)$1;

Read this document to find more details about nginx rewrite rules.

Will the redirect work if lets say I did not add CNAME record to dns? I have already chose my preferred domain in google per your guild above.

You don’t need to add any CNAME record.