创建自己的gem并上传到github

创建自己的gem并上传到github环境:centos7,git version 1.8.3.1

一 创建gem

1 安装bundler#gem install bundler2使用bundler 创建gem所需的框架#bundler gem file_manipulate3修改file_manipulate.gemspec文件#vim file_manipulate.gemspec(主要修改了描述和概要,因为RubyGem实际上不会让spec中的描述包含”TODO“的包,打包至gem中)修改后的file_manipulate.gemspec文件内容如下:# coding: utf-8lib = 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 = "" 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"end4编写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.rb6在file_manipulate.rb中编写具体方法,保存退出#vim file_manipulate.rb7提交到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_manipulate5创建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

转载请注明原文作者:

不会因为忧伤而风情万种。

创建自己的gem并上传到github

相关文章:

你感兴趣的文章:

标签云: