Try this it's working
perfectly :
# Gemfile, run bundle install after adding
gem 'barby'
gem 'chunky_png'
# some code to generate the png file using 3 of 9 barcode style
require 'barby'
require 'barby/barcode/code_128'
require 'barby/outputter/png_outputter'
barcode = Barby::Code128B.new('xxxx')
File.open('exleaz1s.svg', 'wb'){|f|
f.write barcode.to_svg
}