diff --git a/lib/yard/cli/yardoc.rb b/lib/yard/cli/yardoc.rb
index <HASH>..<HASH> 100644
--- a/lib/yard/cli/yardoc.rb
+++ b/lib/yard/cli/yardoc.rb
@@ -220,8 +220,10 @@ module YARD
         @has_markup = false
 
         if defined?(::Encoding) && ::Encoding.respond_to?(:default_external=)
-          ::Encoding.default_external = 'utf-8'
-          ::Encoding.default_internal = 'utf-8'
+          utf8 = ::Encoding.find('utf-8')
+
+          ::Encoding.default_external = utf8 unless ::Encoding.default_external == utf8
+          ::Encoding.default_internal = utf8 unless ::Encoding.default_internal == utf8
         end
       end
Avoid repeated "warning: setting Encoding.default_internal/external"

Instead of always setting the internal/external encoding to utf8, only
change it when it wasn't already utf8.