创建自己的gem并上传到github

1 篇文章 0 订阅
1 篇文章 0 订阅

创建自己的gem并上传到github


环境:centos7,git  version 1.8.3.1


一 创建gem

1 安装bundler 
#gem install bundler


2使用bundler 创建gem所需的框架
#bundler gem file_manipulate


3修改file_manipulate.gemspec文件
#vim file_manipulate.gemspec
(主要修改了描述和概要,因为RubyGem实际上不会让spec中的描述包含”TODO“的包,打包至gem中)
修改后的file_manipulate.gemspec文件内容如下:
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'file_manipulate/version'


Gem::Specification.new do |spec|
  spec.name          = "file_manipulate"
  spec.version       = FileManipulate::VERSION
  spec.authors       = ["liyongkuan"]
  spec.email         = ["lykperson@163.com"]
  spec.summary       = %q{This is a file manipulate library}
  spec.description   = %q{This is a file manipulate library}
  spec.homepage      = "http://blog.csdn.net/li_yong_kuan"
  spec.license       = "MIT"


  spec.files         = `git ls-files -z`.split("\x0")
  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
  spec.require_paths = ["lib"]


  spec.add_development_dependency "bundler", "~> 1.7"
  spec.add_development_dependency "rake", "~> 10.0"
end


4编写lib/file_manipulate.rb文件,把这个文件处理成只是引入库文件的文件
#vim lib/file_manipulate.rb
内容如下:
require "file_manipulate/version"
require "file_manipulate/file_manipulate"
5在lib/file_manipulate下新件file_manipulate.rb文件,在里面写具体做什么事
#touch file_manipulate.rb


6在file_manipulate.rb中编写具体方法,保存退出
#vim file_manipulate.rb


7提交到git
#git add .
#git commit -m "Create a document library operation"


8打包gem
#gem build file_manipulate.gemspec
或者
#rake build


执行完成以后会生成 : file_manipulate-0.0.1.gem   


9 本地安装file_manipulate

#gem install file_manipulate.gem  -l 
 
安装以后,可以 #gem list   查看一下gem列表是否有这个gem

OK,生成gem结束(测试结束后,把file_manipulate.gem删除掉,稍后会把项目上传到github上)



二 上传到github服务器
1在github上创建仓库file_manipulate
详情链接: https://help.github.com/articles/create-a-repo/


2创建密钥 
详细链接: https://help.github.com/articles/generating-ssh-keys/


#ssh-keygen -t rsa -C "lykperson@163.com"


创建结束后会在你的主目录的.ssh 下生成私钥和公钥,我的在
/home/oss/.ssh下(.ssh 是隐藏文件,#ls -a可以查看到)


3复制公钥到github上创建的ssh上,然后自己起一个名字(名字随你自己取)


4进入到我们前面创建的file_manipulate文件下
#cd file_manipulate


5创建url链接的别名
#git remote add kuange git@github.com:liyongkuan/file_manipulate.git


(git@github.com:liyongkuan/file_manipulate.git是操作1创建的仓库ssh地址,在github上可以直接复制)


6把本定项目上传到github上


#git push kuange master 


(kuange 是上一步创建的链接别名)

项目已经上传到github服务器上,链接地址为: https://github.com/liyongkuan/file_manipulate


转载请注明原文作者:  http://blog.csdn.net/li_yong_kuan


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值